import type { ComponentType } from 'react'; import { Navigate, Route, Routes, useLocation, useParams, useSearchParams, } from 'react-router-dom'; import * as CataloguePageModule from '../pages/CataloguePage'; import * as MachineViewerPageModule from '../pages/MachineViewerPage'; import { cataloguePath, machinePath, ROUTE_PATHS } from './routePaths'; type PageComponent = ComponentType>; type PageModuleShape = { default?: PageComponent; CataloguePage?: PageComponent; MachineViewerPage?: PageComponent; }; const cataloguePageModule = CataloguePageModule as unknown as PageModuleShape; const machineViewerPageModule = MachineViewerPageModule as unknown as PageModuleShape; function MissingCataloguePage() { return (

Catalogue unavailable

CataloguePage export could not be resolved

The route shell is loaded, but the catalogue page module did not expose a default or named CataloguePage component.

); } function MissingMachineViewerPage() { const { machineId } = useParams<{ machineId?: string }>(); return (

Viewer page unavailable

MachineViewerPage export could not be resolved

The route layer received machine{' '} {machineId ?? 'unknown'} , but the page module did not expose a default or named MachineViewerPage component.

); } const CataloguePage = cataloguePageModule.default ?? cataloguePageModule.CataloguePage ?? MissingCataloguePage; const MachineViewerPage = machineViewerPageModule.default ?? machineViewerPageModule.MachineViewerPage ?? MissingMachineViewerPage; function preserveLocationSearchAndHash(pathname: string, search: string, hash: string) { return { pathname, search, hash, }; } function LegacyMachineRedirect() { const { machineId } = useParams<{ machineId?: string }>(); const location = useLocation(); if (!machineId) { return ; } return ( ); } function QueryMachineRedirect() { const [searchParams] = useSearchParams(); const location = useLocation(); const machineId = searchParams.get('machine') ?? searchParams.get('machineId') ?? searchParams.get('id'); if (!machineId) { return ; } const nextSearchParams = new URLSearchParams(searchParams); nextSearchParams.delete('machine'); nextSearchParams.delete('machineId'); nextSearchParams.delete('id'); const nextSearch = nextSearchParams.toString(); return ( ); } export function AppRoutes() { return ( } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ); } export default AppRoutes;