fix(router): unblock first login route setup
This commit is contained in:
1 parent
0f2752867c
commit
6d3c640c98
2 files changed
+7
-7
No files matched your search
@@ -47,17 +47,20 @@ router.beforeEach(async (to, _from, next) => {
|
||||
|
||||
const dictStore = useDictStoreWithOut()
|
||||
if (!dictStore.getIsSetDict) {
|
||||
await dictStore.setDictMap()
|
||||
void dictStore.setDictMap().catch((error) => {
|
||||
console.error('[permission] Failed to load dictionaries', error)
|
||||
})
|
||||
}
|
||||
|
||||
const permissionStore = usePermissionStoreWithOut()
|
||||
await permissionStore.generateRoutes(userStore.getMenus)
|
||||
permissionStore.generateRoutes(userStore.getMenus)
|
||||
permissionStore.getAddRouters.forEach((route) => {
|
||||
router.addRoute(route as unknown as RouteRecordRaw)
|
||||
})
|
||||
|
||||
next({ path: to.path, query: to.query, hash: to.hash, replace: true })
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error('[permission] Failed to initialize authenticated routes', error)
|
||||
userStore.resetState()
|
||||
resetRouter()
|
||||
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
|
||||
|
||||
@@ -28,8 +28,7 @@ export const usePermissionStore = defineStore('permission', {
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async generateRoutes(res: AppCustomRouteRecordRaw[] = []): Promise<unknown> {
|
||||
return new Promise<void>(async (resolve) => {
|
||||
generateRoutes(res: AppCustomRouteRecordRaw[] = []): void {
|
||||
// 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
|
||||
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
|
||||
// 动态路由,404一定要放到最后面
|
||||
@@ -46,8 +45,6 @@ export const usePermissionStore = defineStore('permission', {
|
||||
])
|
||||
// 渲染菜单的所有路由
|
||||
this.routers = cloneDeep(remainingRouter).concat(routerMap)
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
setMenuTabRouters(routers: AppRouteRecordRaw[]): void {
|
||||
this.menuTabRouters = routers
|
||||
|
||||
Reference in new issue
Block a user