From d52b0de83e69f7505c28e6f59ec84bbe526ecd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Fri, 2 Jul 2021 00:30:48 +0800 Subject: [PATCH] feat(route): add `hidePathForChildren` in `meta` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加`hidePathForChildren`选项用于在子菜单中隐藏本级path --- src/router/helper/menuHelper.ts | 6 +----- src/router/routes/modules/demo/feat.ts | 1 + types/vue-router.d.ts | 3 +++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/router/helper/menuHelper.ts b/src/router/helper/menuHelper.ts index 84251484..21ed7f07 100644 --- a/src/router/helper/menuHelper.ts +++ b/src/router/helper/menuHelper.ts @@ -9,10 +9,6 @@ export function getAllParentPath(treeData: T[], path: string) { return (menuList || []).map((item) => item.path); } -function isPlainPath(path: string) { - return path.indexOf(':') === -1; -} - function joinParentPath(menus: Menu[], parentPath = '') { for (let index = 0; index < menus.length; index++) { const menu = menus[index]; @@ -24,7 +20,7 @@ function joinParentPath(menus: Menu[], parentPath = '') { menu.path = `${parentPath}/${menu.path}`; } if (menu?.children?.length) { - joinParentPath(menu.children, isPlainPath(menu.path) ? menu.path : parentPath); + joinParentPath(menu.children, menu.meta?.hidePathForChildren ? parentPath : menu.path); } } } diff --git a/src/router/routes/modules/demo/feat.ts b/src/router/routes/modules/demo/feat.ts index c3291b19..3094ead9 100644 --- a/src/router/routes/modules/demo/feat.ts +++ b/src/router/routes/modules/demo/feat.ts @@ -240,6 +240,7 @@ const feat: AppRouteModule = { meta: { title: t('routes.demo.feat.tab'), carryParam: true, + hidePathForChildren: true, }, children: [ { diff --git a/types/vue-router.d.ts b/types/vue-router.d.ts index 2b32346a..c6db921e 100644 --- a/types/vue-router.d.ts +++ b/types/vue-router.d.ts @@ -33,6 +33,9 @@ declare module 'vue-router' { // Never show in menu hideMenu?: boolean; isLink?: boolean; + // only build for Menu ignoreRoute?: boolean; + // Hide path for children + hidePathForChildren?: boolean; } }