From eeb5c55c5ffa85f2d4b3adfbc787d304feb10b9d Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Wed, 7 Aug 2024 09:40:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E5=BD=95=E5=90=8E=E8=AE=BF?= =?UTF-8?q?=E9=97=AE/auth/login=E5=BA=94=E8=AF=A5=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/router/guard.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/web-antd/src/router/guard.ts b/apps/web-antd/src/router/guard.ts index 8ae19c12..1581d015 100644 --- a/apps/web-antd/src/router/guard.ts +++ b/apps/web-antd/src/router/guard.ts @@ -62,14 +62,20 @@ function setupAccessGuard(router: Router) { const userStore = useUserStore(); const authStore = useAuthStore(); + // 基本路由,这些路由不需要进入权限拦截 + if (coreRouteNames.includes(to.name as string)) { + if (to.path === LOGIN_PATH && accessStore.accessToken) { + return decodeURIComponent( + (to.query?.redirect as string) || DEFAULT_HOME_PATH, + ); + } + return true; + } + // accessToken 检查 if (!accessStore.accessToken) { - if ( - // 基本路由,这些路由不需要进入权限拦截 - coreRouteNames.includes(to.name as string) || - // 明确声明忽略权限访问权限,则可以访问 - to.meta.ignoreAccess - ) { + // 明确声明忽略权限访问权限,则可以访问 + if (to.meta.ignoreAccess) { return true; } @@ -87,15 +93,6 @@ function setupAccessGuard(router: Router) { } const accessRoutes = accessStore.accessRoutes; - /** - * 已经登录 前往登录页 跳转到首页 - */ - if (to.path === LOGIN_PATH) { - return { - path: DEFAULT_HOME_PATH, - replace: true, - }; - } // 是否已经生成过动态路由 if (accessRoutes && accessRoutes.length > 0) {