diff --git a/react-ui/src/app.tsx b/react-ui/src/app.tsx index c0ea08c5..16d0e562 100644 --- a/react-ui/src/app.tsx +++ b/react-ui/src/app.tsx @@ -20,7 +20,8 @@ import { setRemoteMenu, } from './services/session'; import './styles/menu.less'; -import { needAuth } from './utils'; +import { isLoginPage, needAuth } from './utils'; +import { HomeUrl } from './utils/constant'; import { closeAllModals } from './utils/modal'; import { gotoLoginPage } from './utils/ui'; export { requestConfig as request } from './requestConfig'; @@ -41,7 +42,7 @@ export async function getInitialState(): Promise { } as API.CurrentUser; } catch (error) { console.error('getInitialState', error); - gotoLoginPage(); + gotoLoginPage(true); } return undefined; }; @@ -117,27 +118,29 @@ export const layout: RuntimeConfig['layout'] = ({ initialState }) => { }; export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => { + debugger; // console.log('onRouteChange'); // 路由切换时,尤其是回退时,关闭打开的弹框 closeAllModals(); const { location } = e; + const pathname = location.pathname; const token = getAccessToken(); // 没有 token,跳转到登录页面 - if (!token && needAuth(location.pathname)) { - gotoLoginPage(); + if (!token && needAuth(pathname)) { + gotoLoginPage(false); return; } // 有 token, 登录页面直接跳转到首页 - if (token && !needAuth(location.pathname)) { - history.push('/'); + if (token && isLoginPage(pathname)) { + history.push(HomeUrl); } const menus = getRemoteMenu(); // 没有菜单,刷新页面 - if (menus === null && needAuth(location.pathname)) { + if (menus === null && needAuth(pathname)) { history.go(0); } }; diff --git a/react-ui/src/components/ErrorBoundary/index.tsx b/react-ui/src/components/ErrorBoundary/index.tsx index 66bc8d94..2483c9e9 100644 --- a/react-ui/src/components/ErrorBoundary/index.tsx +++ b/react-ui/src/components/ErrorBoundary/index.tsx @@ -1,4 +1,5 @@ import KFEmpty, { EmptyType } from '@/components/KFEmpty'; +import { HomeUrl } from '@/utils/constant'; import { Button } from 'antd'; import { Component, ReactNode } from 'react'; @@ -55,7 +56,7 @@ function ErrorBoundaryFallback({ error }: { error: Error | null }) {