Browse Source

fix: redirect use react router pathname

pull/10257/head
chenshuai2144 4 years ago
parent
commit
00151a634b
  1. 39
      src/components/RightContent/AvatarDropdown.tsx

39
src/components/RightContent/AvatarDropdown.tsx

@ -13,27 +13,26 @@ export type GlobalHeaderRightProps = {
menu?: boolean; menu?: boolean;
}; };
/**
* 退 url
*/
const loginOut = async () => {
await outLogin();
const { search, pathname } = window.location;
const urlParams = new URL(window.location.href).searchParams;
/** 此方法会跳转到 redirect 参数所在的位置 */
const redirect = urlParams.get('redirect');
// Note: There may be security issues, please note
if (window.location.pathname !== '/user/login' && !redirect) {
history.replace({
pathname: '/user/login',
search: stringify({
redirect: pathname + search,
}),
});
}
};
const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => { const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
/**
* 退 url
*/
const loginOut = async () => {
await outLogin();
const { search, pathname } = history.location;
const urlParams = new URL(history.location.search).searchParams;
/** 此方法会跳转到 redirect 参数所在的位置 */
const redirect = urlParams.get('redirect');
// Note: There may be security issues, please note
if (window.location.pathname !== '/user/login' && !redirect) {
history.replace({
pathname: '/user/login',
search: stringify({
redirect: pathname + search,
}),
});
}
};
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const onMenuClick = useCallback( const onMenuClick = useCallback(

Loading…
Cancel
Save