refactor: 优化路由守卫错误处理

This commit is contained in:
2025-01-04 19:45:44 +08:00
parent 91092f1cf3
commit aa14d6bdea

View File

@@ -91,7 +91,6 @@ export const setupRouterGuard = (router: Router) => {
next() next()
} else { } else {
if (!hasRouteFlag) { if (!hasRouteFlag) {
try {
await userStore.getInfo() await userStore.getInfo()
if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') { if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') {
Message.warning('密码已过期,请修改密码') Message.warning('密码已过期,请修改密码')
@@ -107,11 +106,6 @@ export const setupRouterGuard = (router: Router) => {
// 确保添加路由已完成 // 确保添加路由已完成
// 设置 replace: true, 因此导航将不会留下历史记录 // 设置 replace: true, 因此导航将不会留下历史记录
next({ ...to, replace: true }) next({ ...to, replace: true })
} catch (error: any) {
// 过程中发生任何错误,都直接重置 Token并重定向到登录页面
await userStore.logoutCallBack()
next(`/login?redirect=${to.path}`)
}
} else { } else {
next() next()
} }