Skip to content

Commit b8353fe

Browse files
committed
fix: fix menu permission failure
1 parent 9abba7a commit b8353fe

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/router/menus/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { transformMenuModule, flatMenus, getAllParentPath } from '/@/utils/helpe
66
import { filter } from '/@/utils/helper/treeHelper';
77
import router from '/@/router';
88
import { PermissionModeEnum } from '/@/enums/appEnum';
9+
import { pathToRegexp } from 'path-to-regexp';
910

1011
// ===========================
1112
// ==========module import====
@@ -106,9 +107,14 @@ export async function getFlatChildrenMenus(children: Menu[]) {
106107
// 通用过滤方法
107108
function basicFilter(routes: RouteRecordNormalized[]) {
108109
return (menu: Menu) => {
109-
const matchRoute = routes.find((route) => route.path === menu.path);
110-
111-
if (!matchRoute) return true;
110+
const matchRoute = routes.find((route) => {
111+
if (route.meta && route.meta.carryParam) {
112+
return pathToRegexp(route.path).test(menu.path);
113+
}
114+
return route.path === menu.path;
115+
});
116+
117+
if (!matchRoute) return false;
112118
menu.icon = menu.icon || matchRoute.meta.icon;
113119
menu.meta = matchRoute.meta;
114120
return true;

src/router/routes/modules/demo/feat.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default {
102102
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
103103
meta: {
104104
title: 'Tab带参',
105+
carryParam: true,
105106
},
106107
},
107108
],

src/router/types.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export interface RouteMeta {
2929

3030
// close loading
3131
afterCloseLoading?: boolean;
32-
32+
// Is it in the tab
3333
inTab?: boolean;
34+
// Carrying parameters
35+
carryParam?: boolean;
3436
}
3537

3638
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {

0 commit comments

Comments
 (0)