fix(auth): 解决登录过期时重复跳转问题

- 避免在已经处于 /login 页面时重复跳转导致的错误
- 添加路由跳转异常捕获防止页面崩溃
- 保持原有的登出和错误提示功能
This commit is contained in:
2026-07-06 15:40:20 +08:00
parent 6282c04f35
commit 5505fc505c

View File

@@ -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 || '网络异常')