web端跳转到登录页的bug修复
This commit is contained in:
Vendored
+1
@@ -10,6 +10,7 @@ interface ImportMetaEnv {
|
|||||||
readonly VITE_DEBUG: string
|
readonly VITE_DEBUG: string
|
||||||
readonly VITE_MOCK: string
|
readonly VITE_MOCK: string
|
||||||
readonly VITE_APP_DESCRIPTION: string
|
readonly VITE_APP_DESCRIPTION: string
|
||||||
|
readonly BASE_URL: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|||||||
@@ -190,8 +190,13 @@ const createAxiosInstance = (): AxiosInstance => {
|
|||||||
const handleUnauthorized = () => {
|
const handleUnauthorized = () => {
|
||||||
console.warn('🚫 收到401未授权响应')
|
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错误')
|
console.log('🚫 当前在登录页面,不处理401错误')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -211,8 +216,8 @@ const handleUnauthorized = () => {
|
|||||||
localStorage.removeItem('refresh_token')
|
localStorage.removeItem('refresh_token')
|
||||||
localStorage.removeItem('user_info')
|
localStorage.removeItem('user_info')
|
||||||
|
|
||||||
// 跳转到登录页
|
// 使用带前缀的完整登录路径,避免 404
|
||||||
window.location.href = '/login'
|
window.location.href = loginPath
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// 用户取消,不清除认证信息,让用户继续操作
|
// 用户取消,不清除认证信息,让用户继续操作
|
||||||
console.log('🚫 用户取消重新登录')
|
console.log('🚫 用户取消重新登录')
|
||||||
|
|||||||
Reference in New Issue
Block a user