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: [