Skip to content

Commit

Permalink
revert: 还原路由守卫错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jan 5, 2025
1 parent d3aeca8 commit a93b88d
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/router/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,27 @@ export const setupRouterGuard = (router: Router) => {
next()
} else {
if (!hasRouteFlag) {
await userStore.getInfo()
if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') {
Message.warning('密码已过期,请修改密码')
next('/pwdExpired')
}
const accessRoutes = await routeStore.generateRoutes()
accessRoutes.forEach((route) => {
if (!isHttp(route.path)) {
router.addRoute(route) // 动态添加可访问路由表
try {
await userStore.getInfo()
if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') {
Message.warning('密码已过期,请修改密码')
next('/pwdExpired')
}
})
hasRouteFlag = true
// 确保添加路由已完成
// 设置 replace: true, 因此导航将不会留下历史记录
next({ ...to, replace: true })
const accessRoutes = await routeStore.generateRoutes()
accessRoutes.forEach((route) => {
if (!isHttp(route.path)) {
router.addRoute(route) // 动态添加可访问路由表
}
})
hasRouteFlag = true
// 确保添加路由已完成
// 设置 replace: true, 因此导航将不会留下历史记录
next({ ...to, replace: true })
} catch (error: any) {
// 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
await userStore.logoutCallBack()
next(`/login?redirect=${to.path}`)
}
} else {
next()
}
Expand Down

0 comments on commit a93b88d

Please sign in to comment.