Skip to content

Commit 6b2fc0a

Browse files
committed
fix(projects): when the roles filter submenu is empty, the parent menu is not excluded
1 parent 740cf4c commit 6b2fc0a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/store/modules/route/shared.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: stri
1919
* @param route Auth route
2020
* @param roles Roles
2121
*/
22-
function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
22+
function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]): ElegantConstRoute[] {
2323
const routeRoles = (route.meta && route.meta.roles) || [];
2424

2525
// if the route's "roles" is empty, then it is allowed to access
@@ -34,6 +34,11 @@ function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
3434
filterRoute.children = filterRoute.children.flatMap(item => filterAuthRouteByRoles(item, roles));
3535
}
3636

37+
// Exclude the route if it has no children after filtering
38+
if (filterRoute.children?.length === 0) {
39+
return [];
40+
}
41+
3742
return hasPermission || isEmptyRoles ? [filterRoute] : [];
3843
}
3944

0 commit comments

Comments
 (0)