From b431c2fcd3afe022f929476d0b92cd1f74965966 Mon Sep 17 00:00:00 2001 From: haitaoo Date: Fri, 24 Feb 2023 14:42:32 +0800 Subject: [PATCH] refactor(router): udpate router errorBoundary --- ui/src/pages/Users/Personal/index.tsx | 2 +- ui/src/router/RouteErrorBoundary.tsx | 8 ++++++++ ui/src/router/index.tsx | 10 ++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 ui/src/router/RouteErrorBoundary.tsx diff --git a/ui/src/pages/Users/Personal/index.tsx b/ui/src/pages/Users/Personal/index.tsx index 1507af6b3..8d40afec2 100644 --- a/ui/src/pages/Users/Personal/index.tsx +++ b/ui/src/pages/Users/Personal/index.tsx @@ -47,7 +47,7 @@ const Personal: FC = () => { tabName, ); let pageTitle = ''; - if (userInfo) { + if (userInfo && userInfo.info && userInfo.has) { pageTitle = `${userInfo.info.display_name} (${userInfo.info.username})`; } const { count = 0, list = [] } = listData?.[tabName] || {}; diff --git a/ui/src/router/RouteErrorBoundary.tsx b/ui/src/router/RouteErrorBoundary.tsx new file mode 100644 index 000000000..d70683e34 --- /dev/null +++ b/ui/src/router/RouteErrorBoundary.tsx @@ -0,0 +1,8 @@ +import Error50X from '@/pages/50X'; +// import Page404 from '@/pages/404'; + +const Index = () => { + return ; +}; + +export default Index; diff --git a/ui/src/router/index.tsx b/ui/src/router/index.tsx index 20f1b5209..2e30ce75f 100644 --- a/ui/src/router/index.tsx +++ b/ui/src/router/index.tsx @@ -2,9 +2,10 @@ import { Suspense, lazy } from 'react'; import { RouteObject } from 'react-router-dom'; import Layout from '@/pages/Layout'; -import ErrorBoundary from '@/pages/50X'; -import baseRoutes, { RouteNode } from '@/router/routes'; -import RouteGuard from '@/router/RouteGuard'; + +import baseRoutes, { RouteNode } from './routes'; +import RouteGuard from './RouteGuard'; +import RouteErrorBoundary from './RouteErrorBoundary'; const routes: RouteNode[] = []; @@ -18,7 +19,7 @@ const routeWrapper = (routeNodes: RouteNode[], root: RouteNode[]) => { ) : ( ); - rn.errorElement = ; + rn.errorElement = ; } else { /** * cannot use a fully dynamic import statement @@ -37,6 +38,7 @@ const routeWrapper = (routeNodes: RouteNode[], root: RouteNode[]) => { )} ); + rn.errorElement = ; } root.push(rn); const children = Array.isArray(rn.children) ? rn.children : null;