fix(router): 修复登录重定向兼容hash路由和普通路由的问题
添加对hash路由的识别处理,优先尝试使用hash路由跳转,失败时回退到普通pathname跳转 docs: 添加Flow架构与执行流程文档
This commit is contained in:
@ -16,8 +16,19 @@ let pendingQueue: { resolve: () => void; reject: (e: unknown) => void; config: R
|
||||
|
||||
function redirectToLogin(msg?: string): Promise<never> {
|
||||
clearToken()
|
||||
if (typeof window !== 'undefined' && window.location.pathname !== '/login') {
|
||||
window.location.href = '/login'
|
||||
if (typeof window !== 'undefined') {
|
||||
const isHashRouter = (window.location.hash || '').startsWith('#/')
|
||||
if (isHashRouter) {
|
||||
if (window.location.hash !== '#/login') {
|
||||
window.location.hash = '#/login'
|
||||
}
|
||||
} else {
|
||||
if (window.location.pathname !== '/login') {
|
||||
// 兼容浏览器路由与生产静态部署:优先使用 hash 入口,无法识别时再回退 pathname
|
||||
try { window.location.hash = '#/login' } catch {}
|
||||
try { window.location.href = '/login' } catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.reject(new Error(msg || '未登录或登录已过期'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user