web端跳转到登录页的bug修复
This commit is contained in:
@@ -190,8 +190,13 @@ const createAxiosInstance = (): AxiosInstance => {
|
||||
const handleUnauthorized = () => {
|
||||
console.warn('🚫 收到401未授权响应')
|
||||
|
||||
// 检查当前页面是否是登录页,避免在登录页面重复处理
|
||||
if (window.location.pathname === '/login') {
|
||||
// 计算当前应用登录页路径,兼容本地和生产环境
|
||||
const base = import.meta.env.BASE_URL || '/'
|
||||
const normalizedBase = base.endsWith('/') ? base : `${base}/`
|
||||
const loginPath = `${normalizedBase}login`
|
||||
|
||||
// 如果已经在登录页,避免重复处理
|
||||
if (window.location.pathname === loginPath) {
|
||||
console.log('🚫 当前在登录页面,不处理401错误')
|
||||
return
|
||||
}
|
||||
@@ -211,8 +216,8 @@ const handleUnauthorized = () => {
|
||||
localStorage.removeItem('refresh_token')
|
||||
localStorage.removeItem('user_info')
|
||||
|
||||
// 跳转到登录页
|
||||
window.location.href = '/login'
|
||||
// 使用带前缀的完整登录路径,避免 404
|
||||
window.location.href = loginPath
|
||||
}).catch(() => {
|
||||
// 用户取消,不清除认证信息,让用户继续操作
|
||||
console.log('🚫 用户取消重新登录')
|
||||
|
||||
Reference in New Issue
Block a user