fix(auth): 解决登录过期时重复跳转问题
- 避免在已经处于 /login 页面时重复跳转导致的错误 - 添加路由跳转异常捕获防止页面崩溃 - 保持原有的登出和错误提示功能
This commit is contained in:
@@ -26,7 +26,10 @@ request.interceptors.response.use(
|
||||
err => {
|
||||
if (err.response?.status === 401) {
|
||||
store.dispatch('auth/logout')
|
||||
router.push('/login')
|
||||
// 避免已经在 /login 时重复跳转报错
|
||||
if (router.currentRoute.path !== '/login') {
|
||||
router.push('/login').catch(() => {})
|
||||
}
|
||||
Message.error('登录已过期,请重新登录')
|
||||
} else {
|
||||
Message.error(err.response?.data?.detail || err.message || '网络异常')
|
||||
|
||||
Reference in New Issue
Block a user