/* Routes, defined in code rather than by file convention. * * One file, flat, so the whole route table is visible at once. TanStack * Router's value here is that is type-checked: a typo in * a path is a build error, not a 404 you find later. */ import { createRootRoute, createRoute, createRouter, } from "@tanstack/react-router"; import { RequireAuth } from "./auth/RequireAuth"; import { AppLayout } from "./components/AppLayout"; import { DevicesPage } from "./pages/DevicesPage"; import { GalleryPage } from "./pages/GalleryPage"; import { SystemPage } from "./pages/SystemPage"; const rootRoute = createRootRoute({ component: AppLayout }); /* Every route is gated. This is the client-side half only -- it decides what * to render, and the server authorises each request independently. A guard * here that the server did not also enforce would be decoration. * * Roles follow SPEC 3.1: the gallery is what a viewer is for, while devices * and system expose operational state and belong to admins. Listing the roles * per route rather than granting admin everything implicitly means widening * one route cannot silently widen another -- the same reasoning as * api/userauth.require_role. */ const galleryRoute = createRoute({ getParentRoute: () => rootRoute, path: "/", component: () => ( ), }); const devicesRoute = createRoute({ getParentRoute: () => rootRoute, path: "/devices", component: () => ( ), }); const systemRoute = createRoute({ getParentRoute: () => rootRoute, path: "/system", component: () => ( ), }); const routeTree = rootRoute.addChildren([galleryRoute, devicesRoute, systemRoute]); export const router = createRouter({ routeTree }); /* Teaches TypeScript about this specific router, which is what makes * paths checked. Without it, `to` is just a string. */ declare module "@tanstack/react-router" { interface Register { router: typeof router; } }