线上环境首页重定向bug修复
This commit is contained in:
@@ -60,9 +60,13 @@ api.interceptors.response.use(
|
||||
localStorage.removeItem('refresh_token');
|
||||
localStorage.removeItem('life_trajectory_v3'); // 清除 Zustand 持久化状态
|
||||
|
||||
// 避免重复跳转导致的无限循环
|
||||
if (window.location.pathname !== '/') {
|
||||
window.location.href = '/';
|
||||
// 避免重复跳转导致的无限循环;使用 Vite 的 BASE_URL 确保在子路径下跳转
|
||||
const baseUrl = (import.meta.env.BASE_URL || '/');
|
||||
const normalize = (p) => (p || '/').replace(/\/+$/, '') || '/';
|
||||
const at = normalize(window.location.pathname);
|
||||
const target = normalize(baseUrl);
|
||||
if (at !== target) {
|
||||
window.location.href = baseUrl; // 仅当不在基路径时跳转
|
||||
}
|
||||
return Promise.reject(new Error('未授权访问,请重新登录'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user