| | |
| | | const tabStore = useTabStore() |
| | | const authStore = useAuthStore() |
| | | const homePath = import.meta.env.VITE_HOME_PATH |
| | | // 公共登录入口落地页:未登录时统一重定向到此,页面挂载后发请求触发 401 跳 SSO 登录。 |
| | | // 不能用 homePath 代替:homePath 可能是需权限的业务页(如 orderManagement), |
| | | // 未登录时其路由被权限过滤不挂载,落 404 后不发任何请求,登录跳转链路断裂。 |
| | | const loginEntryPath = '/dashboard' |
| | | const isStaticRouteMode = import.meta.env.VITE_ROUTE_LOAD_MODE === 'static' |
| | | |
| | | router.beforeEach(async (to, from, next) => { |
| | |
| | | next({ path: homePath, replace: true }) |
| | | } |
| | | else { |
| | | // 未登录,重定向到首页 |
| | | next({ path: homePath, replace: true }) |
| | | // 未登录,重定向到公共落地页,交给 SSO 登录流程 |
| | | next({ path: loginEntryPath, replace: true }) |
| | | } |
| | | return |
| | | } |
| | |
| | | next() |
| | | return |
| | | } |
| | | // 如果路由设置了requiresAuth为true,且用户未登录,重定向到首页(列表页) |
| | | // 如果路由需要登录且用户未登录,统一交给公共落地页(dashboard): |
| | | // 其挂载后 bootstrapAuthEntry 发请求触发 401,由 redirectToSsoAuth 跳 SSO 登录。 |
| | | // 历史教训:旧兜底 `to.path === homePath → next()` 假设 homePath 是公共页; |
| | | // homePath 改为需权限的 orderManagement 后,未登录时路由被过滤落 404, |
| | | // 该兜底直接渲染 404,登录跳转链路断裂。 |
| | | else if (to.meta.requiresAuth !== false && !isLogin) { |
| | | // 避免无限重定向到首页 |
| | | if (to.path === homePath) { |
| | | // 避免落地页自身被无限重定向 |
| | | if (to.path === loginEntryPath) { |
| | | next() |
| | | return |
| | | } |
| | | next({ path: homePath, replace: true }) |
| | | next({ path: loginEntryPath, replace: true }) |
| | | return |
| | | } |
| | | |