web端跳转到登录页的bug修复

This commit is contained in:
2025-11-22 22:36:42 +08:00
parent d7cc96ef07
commit 06a3638c29
2 changed files with 10 additions and 4 deletions
+1
View File
@@ -10,6 +10,7 @@ interface ImportMetaEnv {
readonly VITE_DEBUG: string
readonly VITE_MOCK: string
readonly VITE_APP_DESCRIPTION: string
readonly BASE_URL: string
}
interface ImportMeta {
+9 -4
View File
@@ -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('🚫 用户取消重新登录')