I'm using React Router v6 and following are my routes:
const router = createBrowserRouter([
{
path: '/',
element: <App />,
errorElement: <ErrorPage />,
children: [
{
index: true,
element: <HomePage />,
},
{
path: '/sign-up',
element: <SignUpPage />,
},
{
path: '/log-in',
element: <LogInPage />,
},
],
},
]);
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement,
);
root.render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
);
The App
component contains my app's layout and outputs the route elements using the Outlet
component. But now if there's an error that bubbles up to the root route, then the ErrorPage
gets displayed as expected, but it doesn't make use of the layout from App
... So, how can I reuse my layout from App
when the error page gets displayed?
<AppLayout />
component will be re-created between navigation? No? – Otto