From 00151a634b3b13c712be2d9b4cfe4bf7369ee5da Mon Sep 17 00:00:00 2001 From: chenshuai2144 Date: Sat, 24 Sep 2022 15:34:42 +0800 Subject: [PATCH] fix: redirect use react router pathname --- .../RightContent/AvatarDropdown.tsx | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/components/RightContent/AvatarDropdown.tsx b/src/components/RightContent/AvatarDropdown.tsx index 9e77f15b..380d6bd0 100644 --- a/src/components/RightContent/AvatarDropdown.tsx +++ b/src/components/RightContent/AvatarDropdown.tsx @@ -13,27 +13,26 @@ export type GlobalHeaderRightProps = { 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 = ({ 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 onMenuClick = useCallback(