From f7f647a20cca0d106473e6a862b85d89a7a93d19 Mon Sep 17 00:00:00 2001 From: Your Name <123456> Date: 星期四, 01 十二月 2022 10:59:06 +0800 Subject: [PATCH] 堆栈溢出 --- src/router/index.ts | 46 +++++++++++++++++++++------------------------- 1 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index a99ccfb..322d85c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -66,36 +66,32 @@ // 路由加载前 router.beforeEach(async (to, from, next) => { - if (to.path === '/intelligentLine') { + NProgress.configure({ showSpinner: false }); + if (to.meta.title) NProgress.start(); + const token = Session.get('token'); + if (to.path === '/login' && !token) { next(); + NProgress.done(); } else { - NProgress.configure({ showSpinner: false }); - if (to.meta.title) NProgress.start(); - const token = Session.get('token'); - if (to.path === '/login' && !token) { - next(); + if (!token) { + next(`/login?redirect=${to.path}¶ms=${JSON.stringify(to.query ? to.query : to.params)}`); + Session.clear(); + NProgress.done(); + } else if (token && to.path === '/login') { + next('/home'); NProgress.done(); } else { - if (!token) { - next(`/login?redirect=${to.path}¶ms=${JSON.stringify(to.query ? to.query : to.params)}`); - Session.clear(); - NProgress.done(); - } else if (token && to.path === '/login') { - next('/home'); - NProgress.done(); - } else { - const storesRoutesList = useRoutesList(pinia); - const { routesList } = storeToRefs(storesRoutesList); - if (routesList.value.length === 0) { + const storesRoutesList = useRoutesList(pinia); + const { routesList } = storeToRefs(storesRoutesList); + if (routesList.value.length === 0) { - // 后端控制路由:路由数据初始化,防止刷新时丢失 - await initBackEndControlRoutes(); - // 动态添加路由:防止非首页刷新时跳转回首页的问题 - // 确保 addRoute() 时动态添加的路由已经被完全加载上去 - next({ ...to, replace: true }); - } else { - next(); - } + // 后端控制路由:路由数据初始化,防止刷新时丢失 + await initBackEndControlRoutes(); + // 动态添加路由:防止非首页刷新时跳转回首页的问题 + // 确保 addRoute() 时动态添加的路由已经被完全加载上去 + next({ ...to, replace: true }); + } else { + next(); } } } -- Gitblit v1.9.2