fix(router): unblock first login route setup
This commit is contained in:
1 parent
0f2752867c
commit
6d3c640c98
2 files changed
+22
-22
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,26 +28,23 @@ 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一定要放到最后面
|
this.addRouters = routerMap.concat([
|
||||||
this.addRouters = routerMap.concat([
|
{
|
||||||
{
|
path: '/:path(.*)*',
|
||||||
path: '/:path(.*)*',
|
redirect: '/404',
|
||||||
redirect: '/404',
|
name: '404Page',
|
||||||
name: '404Page',
|
meta: {
|
||||||
meta: {
|
hidden: true,
|
||||||
hidden: true,
|
breadcrumb: false
|
||||||
breadcrumb: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
])
|
}
|
||||||
// 渲染菜单的所有路由
|
])
|
||||||
this.routers = cloneDeep(remainingRouter).concat(routerMap)
|
// 渲染菜单的所有路由
|
||||||
resolve()
|
this.routers = cloneDeep(remainingRouter).concat(routerMap)
|
||||||
})
|
|
||||||
},
|
},
|
||||||
setMenuTabRouters(routers: AppRouteRecordRaw[]): void {
|
setMenuTabRouters(routers: AppRouteRecordRaw[]): void {
|
||||||
this.menuTabRouters = routers
|
this.menuTabRouters = routers
|
||||||
|
|||||||
Reference in new issue
Block a user