From 53de59ea35c54de796b6b09a04f1bfe4589d944b Mon Sep 17 00:00:00 2001 From: Alex Zhu Date: Wed, 29 Apr 2026 19:16:21 +0800 Subject: [PATCH] fix: preserve original URL when redirecting to login (#11722) Co-authored-by: Claude Opus 4.7 --- src/app.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 944fa0b3..50db4597 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -35,7 +35,10 @@ export async function getInitialState(): Promise<{ }); return msg.data; } catch (_error) { - history.push(loginPath); + const { pathname, search, hash } = history.location; + history.replace( + `${loginPath}?redirect=${encodeURIComponent(pathname + search + hash)}`, + ); } return undefined; }; @@ -92,7 +95,9 @@ export const layout: RunTimeLayoutConfig = ({ const { location } = history; // 如果没有登录,重定向到 login if (!initialState?.currentUser && location.pathname !== loginPath) { - history.push(loginPath); + history.replace( + `${loginPath}?redirect=${encodeURIComponent(location.pathname + location.search + location.hash)}`, + ); } }, bgLayoutImgList: [