Commit d52b0de83e69f7505c28e6f59ec84bbe526ecd0d

Authored by 无木
1 parent 72ac240f

feat(route): add `hidePathForChildren` in `meta`

添加`hidePathForChildren`选项用于在子菜单中隐藏本级path
src/router/helper/menuHelper.ts
@@ -9,10 +9,6 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) { @@ -9,10 +9,6 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
9 return (menuList || []).map((item) => item.path); 9 return (menuList || []).map((item) => item.path);
10 } 10 }
11 11
12 -function isPlainPath(path: string) {  
13 - return path.indexOf(':') === -1;  
14 -}  
15 -  
16 function joinParentPath(menus: Menu[], parentPath = '') { 12 function joinParentPath(menus: Menu[], parentPath = '') {
17 for (let index = 0; index < menus.length; index++) { 13 for (let index = 0; index < menus.length; index++) {
18 const menu = menus[index]; 14 const menu = menus[index];
@@ -24,7 +20,7 @@ function joinParentPath(menus: Menu[], parentPath = &#39;&#39;) { @@ -24,7 +20,7 @@ function joinParentPath(menus: Menu[], parentPath = &#39;&#39;) {
24 menu.path = `${parentPath}/${menu.path}`; 20 menu.path = `${parentPath}/${menu.path}`;
25 } 21 }
26 if (menu?.children?.length) { 22 if (menu?.children?.length) {
27 - joinParentPath(menu.children, isPlainPath(menu.path) ? menu.path : parentPath); 23 + joinParentPath(menu.children, menu.meta?.hidePathForChildren ? parentPath : menu.path);
28 } 24 }
29 } 25 }
30 } 26 }
src/router/routes/modules/demo/feat.ts
@@ -240,6 +240,7 @@ const feat: AppRouteModule = { @@ -240,6 +240,7 @@ const feat: AppRouteModule = {
240 meta: { 240 meta: {
241 title: t('routes.demo.feat.tab'), 241 title: t('routes.demo.feat.tab'),
242 carryParam: true, 242 carryParam: true,
  243 + hidePathForChildren: true,
243 }, 244 },
244 children: [ 245 children: [
245 { 246 {
types/vue-router.d.ts
@@ -33,6 +33,9 @@ declare module &#39;vue-router&#39; { @@ -33,6 +33,9 @@ declare module &#39;vue-router&#39; {
33 // Never show in menu 33 // Never show in menu
34 hideMenu?: boolean; 34 hideMenu?: boolean;
35 isLink?: boolean; 35 isLink?: boolean;
  36 + // only build for Menu
36 ignoreRoute?: boolean; 37 ignoreRoute?: boolean;
  38 + // Hide path for children
  39 + hidePathForChildren?: boolean;
37 } 40 }
38 } 41 }