Skip to content

Commit

Permalink
fix(projects): fix repeat routes
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 24, 2024
1 parent 37d20b8 commit 2c543f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const generatedRoutes: GeneratedRoute[] = [
title: '403',
i18nKey: 'route.403',
constant: true,
hideInMenu: true
hideInMenu: true
}
},
{
Expand All @@ -25,7 +25,7 @@ hideInMenu: true
title: '404',
i18nKey: 'route.404',
constant: true,
hideInMenu: true
hideInMenu: true
}
},
{
Expand All @@ -36,7 +36,7 @@ hideInMenu: true
title: '500',
i18nKey: 'route.500',
constant: true,
hideInMenu: true
hideInMenu: true
}
},
{
Expand Down Expand Up @@ -140,7 +140,8 @@ hideInMenu: true
title: 'function_super-page',
i18nKey: 'route.function_super-page',
icon: 'ic:round-supervisor-account',
order: 5
order: 5,
roles: ['R_SUPER']
}
},
{
Expand All @@ -162,8 +163,7 @@ hideInMenu: true
title: 'function_toggle-auth',
i18nKey: 'route.function_toggle-auth',
icon: 'ic:round-construction',
order: 4,
roles: ['R_SUPER']
order: 4
}
}
]
Expand All @@ -188,7 +188,7 @@ hideInMenu: true
title: 'login',
i18nKey: 'route.login',
constant: true,
hideInMenu: true
hideInMenu: true
}
},
{
Expand Down Expand Up @@ -225,7 +225,7 @@ hideInMenu: true
i18nKey: 'route.manage_role',
icon: 'carbon:user-role',
order: 2,
roles: ['R_ADMIN']
roles: ['R_SUPER']
}
},
{
Expand Down
17 changes: 11 additions & 6 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
const authRoutes = shallowRef<ElegantConstRoute[]>([]);

function addAuthRoutes(routes: ElegantConstRoute[]) {
authRoutes.value = [...authRoutes.value, ...routes];
const authRoutesMap = new Map(authRoutes.value.map(route => [route.name, route]));

routes.forEach(route => {
authRoutesMap.set(route.name, route);
});

authRoutes.value = Array.from(authRoutesMap.values());
}

const removeRouteFns: (() => void)[] = [];
Expand Down Expand Up @@ -227,6 +233,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {

const vueRoutes = getAuthVueRoutes(sortRoutes);

resetVueRoutes();

addRoutesToVueRouter(vueRoutes);

getGlobalMenus(sortRoutes);
Expand All @@ -241,10 +249,6 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
*/
function addRoutesToVueRouter(routes: RouteRecordRaw[]) {
routes.forEach(route => {
if (route.name && router.hasRoute(route.name)) {
router.removeRoute(route.name);
}

const removeFn = router.addRoute(route);
addRemoveRouteFn(removeFn);
});
Expand Down Expand Up @@ -291,7 +295,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
}

if (authRouteMode.value === 'static') {
return isRouteExistByRouteName(routeName, authRoutes.value);
const { authRoutes: staticAuthRoutes } = createStaticRoutes();
return isRouteExistByRouteName(routeName, staticAuthRoutes);
}

const { data } = await fetchIsRouteExist(routeName);
Expand Down

0 comments on commit 2c543f1

Please sign in to comment.