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