feat: routers support `ignoreRoute` option
为路由配置添加`meta`.`ignoreRoute`配置,允许在`ROUTE_MAPPING`及`BACK`模式下配置纯菜单数据 fixed:
This commit is contained in:
parent
b5046f07a2
commit
72ac240f28
|
|
@ -9,6 +9,10 @@ export function getAllParentPath<T = Recordable>(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];
|
||||
|
|
@ -20,7 +24,7 @@ function joinParentPath(menus: Menu[], parentPath = '') {
|
|||
menu.path = `${parentPath}/${menu.path}`;
|
||||
}
|
||||
if (menu?.children?.length) {
|
||||
joinParentPath(menu.children, menu.path);
|
||||
joinParentPath(menu.children, isPlainPath(menu.path) ? menu.path : parentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,6 +241,28 @@ const feat: AppRouteModule = {
|
|||
title: t('routes.demo.feat.tab'),
|
||||
carryParam: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'testTab/id1',
|
||||
name: 'TestTab1',
|
||||
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
|
||||
meta: {
|
||||
title: t('routes.demo.feat.tab1'),
|
||||
carryParam: true,
|
||||
ignoreRoute: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'testTab/id2',
|
||||
name: 'TestTab2',
|
||||
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
|
||||
meta: {
|
||||
title: t('routes.demo.feat.tab2'),
|
||||
carryParam: true,
|
||||
ignoreRoute: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -111,6 +111,12 @@ export const usePermissionStore = defineStore({
|
|||
return roleList.some((role) => roles.includes(role));
|
||||
};
|
||||
|
||||
const routeRmoveIgnoreFilter = (route: AppRouteRecordRaw) => {
|
||||
const { meta } = route;
|
||||
const { ignoreRoute } = meta || {};
|
||||
return !ignoreRoute;
|
||||
};
|
||||
|
||||
switch (permissionMode) {
|
||||
case PermissionModeEnum.ROLE:
|
||||
routes = filter(asyncRoutes, routeFilter);
|
||||
|
|
@ -123,6 +129,8 @@ export const usePermissionStore = defineStore({
|
|||
routes = filter(asyncRoutes, routeFilter);
|
||||
routes = routes.filter(routeFilter);
|
||||
const menuList = transformRouteToMenu(routes, true);
|
||||
routes = filter(routes, routeRmoveIgnoreFilter);
|
||||
routes = routes.filter(routeRmoveIgnoreFilter);
|
||||
menuList.sort((a, b) => {
|
||||
return (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0);
|
||||
});
|
||||
|
|
@ -158,6 +166,10 @@ export const usePermissionStore = defineStore({
|
|||
const backMenuList = transformRouteToMenu(routeList);
|
||||
this.setBackMenuList(backMenuList);
|
||||
|
||||
// remove meta.ignoreRoute item
|
||||
routeList = filter(routeList, routeRmoveIgnoreFilter);
|
||||
routeList = routeList.filter(routeRmoveIgnoreFilter);
|
||||
|
||||
routeList = flatMultiLevelRoutes(routeList);
|
||||
routes = [PAGE_NOT_FOUND_ROUTE, ...routeList];
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -33,5 +33,6 @@ declare module 'vue-router' {
|
|||
// Never show in menu
|
||||
hideMenu?: boolean;
|
||||
isLink?: boolean;
|
||||
ignoreRoute?: boolean;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue