From feaf995a4e193535794dc8fad0452b6aaa795bda Mon Sep 17 00:00:00 2001 From: Azir <2075125282@qq.com> Date: Wed, 18 Sep 2024 10:47:45 +0800 Subject: [PATCH] fix(projects): when the roles filter submenu is empty, the parent menu is not excluded. close #621. --- src/store/modules/route/shared.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/store/modules/route/shared.ts b/src/store/modules/route/shared.ts index 1a7afdaab..0686d27e1 100644 --- a/src/store/modules/route/shared.ts +++ b/src/store/modules/route/shared.ts @@ -19,7 +19,7 @@ export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: stri * @param route Auth route * @param roles Roles */ -function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) { +function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]): ElegantConstRoute[] { const routeRoles = (route.meta && route.meta.roles) || []; // if the route's "roles" is empty, then it is allowed to access @@ -34,6 +34,11 @@ function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) { filterRoute.children = filterRoute.children.flatMap(item => filterAuthRouteByRoles(item, roles)); } + // Exclude the route if it has no children after filtering + if (filterRoute.children?.length === 0) { + return []; + } + return hasPermission || isEmptyRoles ? [filterRoute] : []; }