feat(Tabbar): support highlighted with child route (#9926)

This commit is contained in:
chenjiangui 2021-11-24 15:31:10 +08:00 committed by GitHub
parent 3b6f14e57b
commit 3ed8fae93b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -57,10 +57,11 @@ export default defineComponent({
const { $route } = vm; const { $route } = vm;
const { to } = props; const { to } = props;
const config = isObject(to) ? to : { path: to }; const config = isObject(to) ? to : { path: to };
const pathMatched = 'path' in config && config.path === $route.path; return !!$route.matched.find((val) => {
const nameMatched = 'name' in config && config.name === $route.name; const pathMatched = 'path' in config && config.path === val.path;
const nameMatched = 'name' in config && config.name === val.name;
return pathMatched || nameMatched; return pathMatched || nameMatched;
});
} }
return (props.name ?? index.value) === modelValue; return (props.name ?? index.value) === modelValue;

View File

@ -10,6 +10,7 @@ function getMockRouter() {
const $route = reactive({ const $route = reactive({
name: '/', name: '/',
path: '/', path: '/',
matched: [{ name: '/', path: '/' }],
}); });
const push = (val: unknown) => { const push = (val: unknown) => {
if (typeof val === 'string') { if (typeof val === 'string') {
@ -18,6 +19,7 @@ function getMockRouter() {
} else { } else {
Object.assign($route, val); Object.assign($route, val);
} }
$route.matched = [{ name: $route.name, path: $route.path }];
}; };
const $router = { const $router = {
push, push,