线上环境首页重定向bug修复

This commit is contained in:
2025-12-24 23:26:30 +08:00
parent 9b9678b0b6
commit 90d9de0e71
3 changed files with 23 additions and 10 deletions
+7 -3
View File
@@ -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('未授权访问,请重新登录'));
}