feat: add default not found page and dashboard redirect
This commit is contained in:
parent
402b8a6955
commit
3c60261f37
@ -19,16 +19,17 @@ import { ConfigProvider, theme } from 'antd';
|
|||||||
import { useColorSchema } from './store/settings';
|
import { useColorSchema } from './store/settings';
|
||||||
import { StatusPage } from './pages/Status';
|
import { StatusPage } from './pages/Status';
|
||||||
import { TelemetryPage } from './pages/Telemetry';
|
import { TelemetryPage } from './pages/Telemetry';
|
||||||
import { LayoutV2 } from './pages/LayoutV2';
|
|
||||||
import { isDev } from './utils/env';
|
import { isDev } from './utils/env';
|
||||||
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
||||||
import { routeTree } from './routeTree.gen';
|
import { routeTree } from './routeTree.gen';
|
||||||
|
import { DefaultNotFound } from './components/DefaultNotFound';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
routeTree,
|
routeTree,
|
||||||
context: {
|
context: {
|
||||||
userInfo: undefined,
|
userInfo: undefined,
|
||||||
},
|
},
|
||||||
|
defaultNotFoundComponent: DefaultNotFound,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register the router instance for type safety
|
// Register the router instance for type safety
|
||||||
@ -47,7 +48,7 @@ export const AppRoutes: React.FC = React.memo(() => {
|
|||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
{userInfo ? (
|
{userInfo ? (
|
||||||
<Route element={isDev ? <LayoutV2 /> : <Layout />}>
|
<Route element={<Layout />}>
|
||||||
<Route path="/dashboard" element={<DashboardPage />} />
|
<Route path="/dashboard" element={<DashboardPage />} />
|
||||||
<Route path="/monitor/*" element={<MonitorPage />} />
|
<Route path="/monitor/*" element={<MonitorPage />} />
|
||||||
<Route path="/website/*" element={<WebsitePage />} />
|
<Route path="/website/*" element={<WebsitePage />} />
|
||||||
|
10
src/client/components/Code.tsx
Normal file
10
src/client/components/Code.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export const Code: React.FC<React.PropsWithChildren> = React.memo((props) => {
|
||||||
|
return (
|
||||||
|
<span className="rounded-sm border border-zinc-800 bg-zinc-900 px-1 py-0.5">
|
||||||
|
{props.children}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Code.displayName = 'Code';
|
37
src/client/components/DefaultNotFound.tsx
Normal file
37
src/client/components/DefaultNotFound.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Link, useRouterState } from '@tanstack/react-router';
|
||||||
|
import { useTranslation } from '@i18next-toolkit/react';
|
||||||
|
import { Card, CardContent, CardFooter, CardHeader } from './ui/card';
|
||||||
|
import { Code } from './Code';
|
||||||
|
|
||||||
|
export const DefaultNotFound: React.FC = React.memo(() => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const pathname = useRouterState({
|
||||||
|
select: (state) => state.location.pathname,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
|
<Card className="min-w-[320px] bg-zinc-900">
|
||||||
|
<CardHeader>
|
||||||
|
<div className="text-center">
|
||||||
|
<img className="m-auto h-24 w-24" src="/icon.svg" />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="text-center">
|
||||||
|
<div>{t('Sorry, but this page is not found')}</div>
|
||||||
|
<div>
|
||||||
|
<b>{t('Path')}</b>: <Code>{pathname}</Code>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter>
|
||||||
|
<Link className="ml-auto" to="/">
|
||||||
|
<Button>{t('Back to Homepage')}</Button>
|
||||||
|
</Link>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
DefaultNotFound.displayName = 'DefaultNotFound';
|
@ -15,6 +15,7 @@ import { Route as WebsiteImport } from './routes/website'
|
|||||||
import { Route as RegisterImport } from './routes/register'
|
import { Route as RegisterImport } from './routes/register'
|
||||||
import { Route as MonitorImport } from './routes/monitor'
|
import { Route as MonitorImport } from './routes/monitor'
|
||||||
import { Route as LoginImport } from './routes/login'
|
import { Route as LoginImport } from './routes/login'
|
||||||
|
import { Route as DashboardImport } from './routes/dashboard'
|
||||||
import { Route as IndexImport } from './routes/index'
|
import { Route as IndexImport } from './routes/index'
|
||||||
import { Route as WebsiteAddImport } from './routes/website/add'
|
import { Route as WebsiteAddImport } from './routes/website/add'
|
||||||
import { Route as WebsiteWebsiteIdImport } from './routes/website/$websiteId'
|
import { Route as WebsiteWebsiteIdImport } from './routes/website/$websiteId'
|
||||||
@ -43,6 +44,11 @@ const LoginRoute = LoginImport.update({
|
|||||||
getParentRoute: () => rootRoute,
|
getParentRoute: () => rootRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
|
const DashboardRoute = DashboardImport.update({
|
||||||
|
path: '/dashboard',
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
const IndexRoute = IndexImport.update({
|
const IndexRoute = IndexImport.update({
|
||||||
path: '/',
|
path: '/',
|
||||||
getParentRoute: () => rootRoute,
|
getParentRoute: () => rootRoute,
|
||||||
@ -76,6 +82,10 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof IndexImport
|
preLoaderRoute: typeof IndexImport
|
||||||
parentRoute: typeof rootRoute
|
parentRoute: typeof rootRoute
|
||||||
}
|
}
|
||||||
|
'/dashboard': {
|
||||||
|
preLoaderRoute: typeof DashboardImport
|
||||||
|
parentRoute: typeof rootRoute
|
||||||
|
}
|
||||||
'/login': {
|
'/login': {
|
||||||
preLoaderRoute: typeof LoginImport
|
preLoaderRoute: typeof LoginImport
|
||||||
parentRoute: typeof rootRoute
|
parentRoute: typeof rootRoute
|
||||||
@ -115,6 +125,7 @@ declare module '@tanstack/react-router' {
|
|||||||
|
|
||||||
export const routeTree = rootRoute.addChildren([
|
export const routeTree = rootRoute.addChildren([
|
||||||
IndexRoute,
|
IndexRoute,
|
||||||
|
DashboardRoute,
|
||||||
LoginRoute,
|
LoginRoute,
|
||||||
MonitorRoute.addChildren([MonitorMonitorIdRoute, MonitorAddRoute]),
|
MonitorRoute.addChildren([MonitorMonitorIdRoute, MonitorAddRoute]),
|
||||||
RegisterRoute,
|
RegisterRoute,
|
||||||
|
9
src/client/routes/dashboard.tsx
Normal file
9
src/client/routes/dashboard.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { createFileRoute, redirect } from '@tanstack/react-router';
|
||||||
|
|
||||||
|
export const Route = createFileRoute('/dashboard')({
|
||||||
|
beforeLoad: () => {
|
||||||
|
redirect({
|
||||||
|
to: '/',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@ -9,6 +9,7 @@ module.exports = {
|
|||||||
relative: true,
|
relative: true,
|
||||||
files: [
|
files: [
|
||||||
'./index.html',
|
'./index.html',
|
||||||
|
'./App.tsx',
|
||||||
'./components/**/*.{js,jsx,ts,tsx}',
|
'./components/**/*.{js,jsx,ts,tsx}',
|
||||||
'./pages/**/*.{js,jsx,ts,tsx}',
|
'./pages/**/*.{js,jsx,ts,tsx}',
|
||||||
'./routes/**/*.{js,jsx,ts,tsx}',
|
'./routes/**/*.{js,jsx,ts,tsx}',
|
||||||
|
Loading…
Reference in New Issue
Block a user