From d0d02d71289cd2793dd32f0efc34d8ea011bde22 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Tue, 8 Nov 2022 18:18:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=AE=88=E5=8D=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index fd0d5cc..e90b6c6 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -109,6 +109,10 @@ router.beforeEach((to: toRouteType, _from, next) => { else document.title = transformI18n(item.meta.title); }); } + /** 如果已经登录并存在登录信息后不能跳转到路由白名单,而是继续保持在当前页面 */ + function toCorrectRoute() { + whiteList.includes(to.fullPath) ? next(_from.fullPath) : next(); + } if (userInfo) { // 无权限跳转403页面 if (to.meta?.roles && !isOneOfArray(to.meta?.roles, userInfo?.roles)) { @@ -120,7 +124,7 @@ router.beforeEach((to: toRouteType, _from, next) => { openLink(to?.name as string); NProgress.done(); } else { - next(); + toCorrectRoute(); } } else { // 刷新 @@ -150,7 +154,7 @@ router.beforeEach((to: toRouteType, _from, next) => { } router.push(to.fullPath); }); - next(); + toCorrectRoute(); } } else { if (to.path !== "/login") {