fix(auth): 修复401重定向死循环和返回报错问题
核心改动: 1. 401拦截器智能选择跳转方式 - 导航栈只有1页时使用 reLaunch(清空栈) - 导航栈有多页时使用 redirectTo(替换当前页) - 保存当前路径到 router store(用于登录后跳回) 2. NavHeader组件智能返回逻辑 - 检查导航栈长度 - 导航栈只有1页时跳转首页(避免返回报错) - 导航栈有多页时正常返回 3. 登录页智能跳转 - 登录成功后读取 router store 保存的路径 - 有保存路径则跳转回原页面 - 无保存路径则跳转到首页 解决问题: - ✅ 修复401重定向导致的死循环问题 - ✅ 修复登录页点击返回报错 "navigateBack:fail cannot navigate back at first page" - ✅ 提升用户体验(登录后回到原页面而非总是首页) 技术细节: - 正确使用 Pinia store:const store = routerStore() - 理解导航 API 差异:navigateTo(入栈)、redirectTo(替换)、reLaunch(清空栈) 影响文件: - src/utils/request.js - 401拦截器优化 - src/components/NavHeader.vue - 返回逻辑优化 - src/pages/login/index.vue - 登录成功后智能跳转 - components.d.ts - TypeScript声明自动更新 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Showing
4 changed files
with
68 additions
and
4 deletions
-
Please register or login to post a comment