From 3ed8fae93b8345354e006a07b5e091c8aeb338c5 Mon Sep 17 00:00:00 2001 From: chenjiangui <674149625@qq.com> Date: Wed, 24 Nov 2021 15:31:10 +0800 Subject: [PATCH] feat(Tabbar): support highlighted with child route (#9926) --- packages/vant/src/tabbar-item/TabbarItem.tsx | 9 +++++---- packages/vant/src/tabbar/test/index.spec.tsx | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vant/src/tabbar-item/TabbarItem.tsx b/packages/vant/src/tabbar-item/TabbarItem.tsx index 328b26546..26a225ed0 100644 --- a/packages/vant/src/tabbar-item/TabbarItem.tsx +++ b/packages/vant/src/tabbar-item/TabbarItem.tsx @@ -57,10 +57,11 @@ export default defineComponent({ const { $route } = vm; const { to } = props; const config = isObject(to) ? to : { path: to }; - const pathMatched = 'path' in config && config.path === $route.path; - const nameMatched = 'name' in config && config.name === $route.name; - - return pathMatched || nameMatched; + return !!$route.matched.find((val) => { + const pathMatched = 'path' in config && config.path === val.path; + const nameMatched = 'name' in config && config.name === val.name; + return pathMatched || nameMatched; + }); } return (props.name ?? index.value) === modelValue; diff --git a/packages/vant/src/tabbar/test/index.spec.tsx b/packages/vant/src/tabbar/test/index.spec.tsx index 5f2ae7562..7d422e991 100644 --- a/packages/vant/src/tabbar/test/index.spec.tsx +++ b/packages/vant/src/tabbar/test/index.spec.tsx @@ -10,6 +10,7 @@ function getMockRouter() { const $route = reactive({ name: '/', path: '/', + matched: [{ name: '/', path: '/' }], }); const push = (val: unknown) => { if (typeof val === 'string') { @@ -18,6 +19,7 @@ function getMockRouter() { } else { Object.assign($route, val); } + $route.matched = [{ name: $route.name, path: $route.path }]; }; const $router = { push,