NTP_V2/web/src/App.tsx

41 lines
1.3 KiB
TypeScript

import { useEffect, useMemo } from 'react';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import { useToast } from '@/providers/ToastProvider';
import { featureRoutes } from '@/registry';
import { AppShell } from '@/shell/AppShell';
import { DashboardPage } from '@/shell/DashboardPage';
import { NotFoundPage } from '@/shell/ErrorPages';
import { LoginPage } from '@/shell/LoginPage';
import { ProtectedRoute } from '@/shell/ProtectedRoute';
export function App() {
const router = useMemo(
() =>
createBrowserRouter([
{ path: '/login', element: <LoginPage /> },
{
element: <ProtectedRoute />,
children: [
{
element: <AppShell />,
children: [{ index: true, element: <DashboardPage /> }, ...featureRoutes, { path: '*', element: <NotFoundPage /> }],
},
],
},
]),
[],
);
// a response message does not follow the user to another page
const toast = useToast();
useEffect(() => {
let path = router.state.location.pathname;
return router.subscribe((state) => {
if (state.location.pathname !== path) {
path = state.location.pathname;
toast.dismissOnNavigate();
}
});
}, [router, toast]);
return <RouterProvider router={router} />;
}