diff --git a/src/router/elegant/routes.ts b/src/router/elegant/routes.ts index cf451171e..c8a514d80 100644 --- a/src/router/elegant/routes.ts +++ b/src/router/elegant/routes.ts @@ -14,7 +14,7 @@ export const generatedRoutes: GeneratedRoute[] = [ title: '403', i18nKey: 'route.403', constant: true, -hideInMenu: true + hideInMenu: true } }, { @@ -25,7 +25,7 @@ hideInMenu: true title: '404', i18nKey: 'route.404', constant: true, -hideInMenu: true + hideInMenu: true } }, { @@ -36,7 +36,7 @@ hideInMenu: true title: '500', i18nKey: 'route.500', constant: true, -hideInMenu: true + hideInMenu: true } }, { @@ -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'] } }, { @@ -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 } } ] @@ -188,7 +188,7 @@ hideInMenu: true title: 'login', i18nKey: 'route.login', constant: true, -hideInMenu: true + hideInMenu: true } }, { @@ -225,7 +225,7 @@ hideInMenu: true i18nKey: 'route.manage_role', icon: 'carbon:user-role', order: 2, - roles: ['R_ADMIN'] + roles: ['R_SUPER'] } }, { diff --git a/src/store/modules/route/index.ts b/src/store/modules/route/index.ts index 7a845db16..168001738 100644 --- a/src/store/modules/route/index.ts +++ b/src/store/modules/route/index.ts @@ -56,7 +56,13 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { const authRoutes = shallowRef([]); 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)[] = []; @@ -227,6 +233,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { const vueRoutes = getAuthVueRoutes(sortRoutes); + resetVueRoutes(); + addRoutesToVueRouter(vueRoutes); getGlobalMenus(sortRoutes); @@ -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); }); @@ -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);