From bf9f6f9a0d920b37ca74b2c200c6f87c0a5ecdf1 Mon Sep 17 00:00:00 2001 From: xachary <179740385@qq.com> Date: Tue, 27 Feb 2024 11:12:14 +0800 Subject: [PATCH] fix(Login): avoid infinite loop when query redirect to next route redirect --- src/router/guard/permissionGuard.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/router/guard/permissionGuard.ts b/src/router/guard/permissionGuard.ts index 07bd7ea4822..9ae9d7069ce 100644 --- a/src/router/guard/permissionGuard.ts +++ b/src/router/guard/permissionGuard.ts @@ -113,6 +113,11 @@ export function createPermissionGuard(router: Router) { } else if (from.query.redirect) { // 存在redirect const redirect = decodeURIComponent((from.query.redirect as string) || ''); + + // 只处理一次 from.query.redirect + // 也避免某场景(指向路由定义了 redirect)下的死循环 + from.query.redirect = ''; + if (redirect === to.fullPath) { // 已经被redirect next(); @@ -120,6 +125,7 @@ export function createPermissionGuard(router: Router) { // 指向redirect next({ path: redirect, replace: true }); } + next(); } else { // 正常访问 next();