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,