mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 15:36:18 -05:00
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:
parent
d75be8e1a4
commit
bb8945e8ad
2 changed files with 61 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue