fix(TabBar): route matching in special cases (#10447)

This commit is contained in:
Zhong Lufan
2022-03-30 09:35:16 +08:00
committed by GitHub
parent cda29f68fe
commit daaaa84945
3 changed files with 14 additions and 11 deletions
+12 -9
View File
@@ -32,19 +32,22 @@ export default createComponent({
},
computed: {
routeMatched() {
const { to, $route } = this;
if (to && $route) {
active() {
const routeMode = this.parent.route;
if (routeMode && '$route' in this) {
const { to, $route } = this;
const config = isObject(to) ? to : { path: to };
return !!$route.matched.find(r =>{
const pathMatched = config.path === r.path;
return !!$route.matched.find((r) => {
// vue-router 3.x $route.matched[0].path is empty in / and its children paths
const path = r.path === '' ? '/' : r.path;
const pathMatched = config.path === path;
const nameMatched = isDef(config.name) && config.name === r.name;
return pathMatched || nameMatched;
})
});
}
},
active() {
return this.parent.route ? this.routeMatched : this.nameMatched;
return this.nameMatched;
},
},