diff --git a/packages/core/client/src/user/CurrentUserProvider.tsx b/packages/core/client/src/user/CurrentUserProvider.tsx
index 49403cd06..85ed2b133 100644
--- a/packages/core/client/src/user/CurrentUserProvider.tsx
+++ b/packages/core/client/src/user/CurrentUserProvider.tsx
@@ -1,6 +1,6 @@
import { Spin } from 'antd';
import React, { createContext, useContext } from 'react';
-import { Redirect } from 'react-router-dom';
+import { Redirect, useLocation } from 'react-router-dom';
import { useRequest } from '../api-client';
export const CurrentUserContext = createContext(null);
@@ -10,14 +10,17 @@ export const useCurrentUserContext = () => {
}
export const CurrentUserProvider = (props) => {
+ const location = useLocation();
const result = useRequest({
url: 'users:check',
});
if (result.loading) {
return ;
}
+ const { pathname, search } = location;
+ let redirect = `?redirect=${pathname}${search}`;
if (!result?.data?.data?.id) {
- return ;
+ return ;
}
return {props.children};
};
diff --git a/packages/core/client/src/user/SigninPage.tsx b/packages/core/client/src/user/SigninPage.tsx
index 5be8e6b8e..c14793975 100644
--- a/packages/core/client/src/user/SigninPage.tsx
+++ b/packages/core/client/src/user/SigninPage.tsx
@@ -1,7 +1,7 @@
import { ISchema, useForm } from '@formily/react';
import { uid } from '@formily/shared';
import React from 'react';
-import { useHistory } from 'react-router-dom';
+import { useHistory, useLocation } from 'react-router-dom';
import { SchemaComponent, useAPIClient, useCurrentDocumentTitle, useSystemSettings } from '..';
const schema: ISchema = {
@@ -60,9 +60,11 @@ const schema: ISchema = {
};
const useSignin = () => {
+ const location = useLocation();
const history = useHistory();
const form = useForm();
const api = useAPIClient();
+ const redirect = location?.['query']?.redirect;
return {
async run() {
await form.submit();
@@ -71,7 +73,7 @@ const useSignin = () => {
});
if (response?.data?.data?.token) {
api.setBearerToken(response?.data?.data?.token);
- history.push('/admin');
+ history.push(redirect || '/admin');
}
},
};