Skip to content

Commit

Permalink
fix(projects): when the roles filter submenu is empty, the parent men…
Browse files Browse the repository at this point in the history
…u is not excluded. fixed #621. (#626)
  • Loading branch information
Azir-11 authored Sep 18, 2024
1 parent 04d0564 commit 0ac95bd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/store/modules/route/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] : [];
}

Expand Down

0 comments on commit 0ac95bd

Please sign in to comment.