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 9 return (menuList || []).map((item) => item.path);
10 10 }
11 11  
12   -function isPlainPath(path: string) {
13   - return path.indexOf(':') === -1;
14   -}
15   -
16 12 function joinParentPath(menus: Menu[], parentPath = '') {
17 13 for (let index = 0; index < menus.length; index++) {
18 14 const menu = menus[index];
... ... @@ -24,7 +20,7 @@ function joinParentPath(menus: Menu[], parentPath = &#39;&#39;) {
24 20 menu.path = `${parentPath}/${menu.path}`;
25 21 }
26 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 240 meta: {
241 241 title: t('routes.demo.feat.tab'),
242 242 carryParam: true,
  243 + hidePathForChildren: true,
243 244 },
244 245 children: [
245 246 {
... ...
types/vue-router.d.ts
... ... @@ -33,6 +33,9 @@ declare module &#39;vue-router&#39; {
33 33 // Never show in menu
34 34 hideMenu?: boolean;
35 35 isLink?: boolean;
  36 + // only build for Menu
36 37 ignoreRoute?: boolean;
  38 + // Hide path for children
  39 + hidePathForChildren?: boolean;
37 40 }
38 41 }
... ...