Skip to content

Commit

Permalink
refactor(router): udpate router errorBoundary
Browse files Browse the repository at this point in the history
  • Loading branch information
haitaoo committed Feb 24, 2023
1 parent d133587 commit b431c2f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/src/pages/Users/Personal/index.tsx
Expand Up @@ -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] || {};
Expand Down
8 changes: 8 additions & 0 deletions ui/src/router/RouteErrorBoundary.tsx
@@ -0,0 +1,8 @@
import Error50X from '@/pages/50X';
// import Page404 from '@/pages/404';

const Index = () => {
return <Error50X />;
};

export default Index;
10 changes: 6 additions & 4 deletions ui/src/router/index.tsx
Expand Up @@ -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[] = [];

Expand All @@ -18,7 +19,7 @@ const routeWrapper = (routeNodes: RouteNode[], root: RouteNode[]) => {
) : (
<Layout />
);
rn.errorElement = <ErrorBoundary />;
rn.errorElement = <RouteErrorBoundary />;
} else {
/**
* cannot use a fully dynamic import statement
Expand All @@ -37,6 +38,7 @@ const routeWrapper = (routeNodes: RouteNode[], root: RouteNode[]) => {
)}
</Suspense>
);
rn.errorElement = <RouteErrorBoundary />;
}
root.push(rn);
const children = Array.isArray(rn.children) ? rn.children : null;
Expand Down

0 comments on commit b431c2f

Please sign in to comment.