Render unknown URLs as a 404 page inside the app layout (#805)

An unknown URL (e.g. /archive instead of /archives) had no matching route,
so react-router rendered the root errorElement in place of Root.  That put
PageNotFound outside ThemeProvider, and its Mantine Box threw
"MantineProvider was not found", leaving a blank page.

- A catch-all route renders PageNotFound inside Root, with the navigation
  bar, footer and theme.
- The root errorElement brings its own ThemeProvider, so it can render when
  Root itself fails.
- App exports its routes so a test can mount them in a memory router.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-10-09 15:00:36 -06:00 • committed by GitHub
parent d75be8e1a4
commit bb8945e8ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 3 deletions

View file

@ -87,10 +87,12 @@ function Root() {
</QueryProvider>
}
const router = createBrowserRouter(createRoutesFromElements(<Route
export const routes = createRoutesFromElements(<Route
path='/'
element={<Root/>}
errorElement={<PageNotFound/>}
// Root (and its ThemeProvider) is not rendered when Root itself fails, so the error page
// brings its own theme; Mantine components cannot render without one.
errorElement={<ThemeProvider><PageNotFound/></ThemeProvider>}
>
<Route index element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
<Route path='search/*' element={<ErrorBoundary><DashboardPage/></ErrorBoundary>}/>
@ -121,7 +123,11 @@ const router = createBrowserRouter(createRoutesFromElements(<Route
<Route path='repos/*' element={<ErrorBoundary><ReposRoute/></ErrorBoundary>}/>
<Route path='files/*' element={<ErrorBoundary><FilesRoute/></ErrorBoundary>}/>
<Route path='flasher/*' element={<ErrorBoundary><FlasherRoute/></ErrorBoundary>}/>
</Route>));
{/* Unknown URLs render inside Root, with the navigation bar and theme. */}
<Route path='*' element={<PageNotFound/>}/>
</Route>);
const router = createBrowserRouter(routes);
export default function App() {
useEventsInterval();