AFFiNE/packages/frontend/admin/src/app.tsx

89 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-06-18 09:01:13 +03:00
import { Toaster } from '@affine/admin/components/ui/sonner';
import { Telemetry } from '@affine/core/telemetry';
import { wrapCreateBrowserRouter } from '@sentry/react';
import { useEffect } from 'react';
import {
createBrowserRouter as reactRouterCreateBrowserRouter,
RouterProvider,
useLocation,
useNavigate,
} from 'react-router-dom';
import { TooltipProvider } from './components/ui/tooltip';
const createBrowserRouter = wrapCreateBrowserRouter(
reactRouterCreateBrowserRouter
);
const _createBrowserRouter = window.SENTRY_RELEASE
? createBrowserRouter
: reactRouterCreateBrowserRouter;
const Redirect = function Redirect() {
const location = useLocation();
const navigate = useNavigate();
useEffect(() => {
if (!location.pathname.startsWith('/admin/accounts')) {
navigate('/admin/accounts', { replace: true });
2024-06-18 09:01:13 +03:00
}
}, [location, navigate]);
return null;
};
export const router = _createBrowserRouter(
[
{
path: '/',
element: <Redirect />,
},
{
path: '/admin',
children: [
{
path: '',
element: <Redirect />,
},
{
path: '/admin/accounts',
lazy: () => import('./modules/accounts'),
2024-06-18 09:01:13 +03:00
},
{
path: '/admin/auth',
lazy: () => import('./modules/auth'),
},
{
path: '/admin/ai',
lazy: () => import('./modules/ai'),
},
2024-06-18 09:01:13 +03:00
{
path: '/admin/setup',
lazy: () => import('./modules/setup'),
2024-06-18 09:01:13 +03:00
},
{
path: '/admin/config',
lazy: () => import('./modules/config'),
},
{
path: '/admin/settings',
lazy: () => import('./modules/settings'),
},
2024-06-18 09:01:13 +03:00
],
},
],
{
future: {
v7_normalizeFormMethod: true,
},
}
);
export const App = () => {
return (
<TooltipProvider>
<Telemetry />
<RouterProvider router={router} />
<Toaster />
</TooltipProvider>
);
};