2026-06-28 15:02:07 +02:00
|
|
|
import { createBrowserRouter, Navigate, type RouteObject } from 'react-router'
|
|
|
|
|
import LoginPage from './auth/LoginPage'
|
2026-06-28 16:33:32 +02:00
|
|
|
import RegisterPage from './auth/RegisterPage'
|
2026-06-28 15:02:07 +02:00
|
|
|
import { RequireAuth, RequireGuest } from './auth/guards'
|
2026-07-05 23:27:17 +02:00
|
|
|
import ScenarioShowPage from './pages/ScenarioShowPage'
|
2026-06-28 15:02:07 +02:00
|
|
|
import ScenariosPage from './pages/ScenariosPage'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Application route tree. Guards are layout routes: their children render via
|
|
|
|
|
* <Outlet /> only when the guard allows it (RequireGuest = signed-out users,
|
|
|
|
|
* RequireAuth = signed-in users). Add new pages as children of the appropriate
|
|
|
|
|
* guard.
|
|
|
|
|
*
|
|
|
|
|
* Exported as a plain array so tests can drive the real route config through
|
|
|
|
|
* createMemoryRouter (see router.test.tsx).
|
|
|
|
|
*/
|
|
|
|
|
export const routes: RouteObject[] = [
|
|
|
|
|
{
|
|
|
|
|
element: <RequireGuest />,
|
|
|
|
|
children: [
|
|
|
|
|
{ path: '/login', element: <LoginPage /> },
|
2026-06-28 16:33:32 +02:00
|
|
|
{ path: '/register', element: <RegisterPage /> },
|
2026-06-28 15:02:07 +02:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
element: <RequireAuth />,
|
2026-07-05 23:27:17 +02:00
|
|
|
children: [
|
|
|
|
|
{ path: '/', element: <ScenariosPage /> },
|
|
|
|
|
{ path: '/scenarios/:id', element: <ScenarioShowPage /> },
|
|
|
|
|
],
|
2026-06-28 15:02:07 +02:00
|
|
|
},
|
|
|
|
|
// Unknown paths fall back to the app root (which re-guards).
|
|
|
|
|
{ path: '*', element: <Navigate to="/" replace /> },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export const router = createBrowserRouter(routes)
|