From 22bf644b3fc85763be3ad0c5e348d2bee38e2444 Mon Sep 17 00:00:00 2001 From: 马宇豪 <978517621@qq.com> Date: 星期三, 22 三月 2023 17:07:48 +0800 Subject: [PATCH] Default Changelist --- src/router/index.ts | 45 +++++++++++++++++++++------------------------ 1 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 11ec534..322d85c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -66,35 +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('/homeMenu'); - NProgress.done(); + const storesRoutesList = useRoutesList(pinia); + const { routesList } = storeToRefs(storesRoutesList); + if (routesList.value.length === 0) { + + // 后端控制路由:路由数据初始化,防止刷新时丢失 + await initBackEndControlRoutes(); + // 动态添加路由:防止非首页刷新时跳转回首页的问题 + // 确保 addRoute() 时动态添加的路由已经被完全加载上去 + next({ ...to, replace: true }); } else { - const storesRoutesList = useRoutesList(pinia); - const { routesList } = storeToRefs(storesRoutesList); - if (routesList.value.length === 0) { - // 后端控制路由:路由数据初始化,防止刷新时丢失 - await initBackEndControlRoutes(); - // 动态添加路由:防止非首页刷新时跳转回首页的问题 - // 确保 addRoute() 时动态添加的路由已经被完全加载上去 - next({ ...to, replace: true }); - } else { - next(); - } + next(); } } } -- Gitblit v1.9.2