From 51464d85d537809f1022585e977e1cb30b791def Mon Sep 17 00:00:00 2001 From: sunlei Date: Mon, 18 May 2026 21:21:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E5=A4=8D=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=8E=AF=E5=A2=83=E7=99=BB=E5=BD=95=E5=9B=9E=E8=B7=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antdv-next/.env.development | 1 + apps/web-antdv-next/src/router/guard.ts | 16 +++++++++++++++- apps/web-antdv-next/src/store/auth.ts | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/web-antdv-next/.env.development b/apps/web-antdv-next/.env.development index 3a91dad..3b8df81 100644 --- a/apps/web-antdv-next/.env.development +++ b/apps/web-antdv-next/.env.development @@ -2,6 +2,7 @@ VITE_PORT=5999 VITE_BASE=/ +VITE_ROUTER_HISTORY=hash # 接口地址 VITE_GLOB_API_URL=/api diff --git a/apps/web-antdv-next/src/router/guard.ts b/apps/web-antdv-next/src/router/guard.ts index 3290d7b..3ac15f2 100644 --- a/apps/web-antdv-next/src/router/guard.ts +++ b/apps/web-antdv-next/src/router/guard.ts @@ -28,7 +28,21 @@ function getRedirectQuery(queryRedirect?: string) { if (queryRedirect) return queryRedirect; // 兼容旧链接 /auth/login?redirect=... 在 hash 路由下被放到 location.search 的情况。 - return new URLSearchParams(window.location.search).get('redirect') || ''; + const searchRedirect = new URLSearchParams(window.location.search).get( + 'redirect', + ); + if (searchRedirect) return searchRedirect; + + // Web/Playground 生产配置会跳 /#/auth/login?redirect=...; + // Admin 本地 history 模式下该 query 只存在于 location.hash。 + const hashQueryIndex = window.location.hash.indexOf('?'); + if (hashQueryIndex === -1) return ''; + + return ( + new URLSearchParams(window.location.hash.slice(hashQueryIndex + 1)).get( + 'redirect', + ) || '' + ); } /** diff --git a/apps/web-antdv-next/src/store/auth.ts b/apps/web-antdv-next/src/store/auth.ts index 5925bec..f85c038 100644 --- a/apps/web-antdv-next/src/store/auth.ts +++ b/apps/web-antdv-next/src/store/auth.ts @@ -38,9 +38,19 @@ export const useAuthStore = defineStore('auth', () => { if (routeRedirect) return routeRedirect; // 兼容旧链接 /auth/login?redirect=... 在 hash 路由下被放到 location.search 的情况。 - return new URLSearchParams(window.location.search).get('redirect') as - | null - | string; + const searchRedirect = new URLSearchParams(window.location.search).get( + 'redirect', + ); + if (searchRedirect) return searchRedirect; + + // Web/Playground 生产配置会跳 /#/auth/login?redirect=...; + // Admin 本地 history 模式下该 query 只存在于 location.hash。 + const hashQueryIndex = window.location.hash.indexOf('?'); + if (hashQueryIndex === -1) return null; + + return new URLSearchParams( + window.location.hash.slice(hashQueryIndex + 1), + ).get('redirect'); } function buildExternalAuthRedirectUrl(target: string) {