Even in react-router-dom@6.4.0
, routing with generic UI rendering layout still works fine.
Create a layout route component that renders the public header component and an Outlet
for nested routes.
Example:
const Layout = () => ( <> <CommonHeader /> <Outlet /> </> );
Import and render Layout
on the layout route in the configuration.
const routers = createBrowserRouter([ { element: <Layout />, children: [ { path: "/", element: <Home />, loader: authLoader }, { path: "/about", element: <About /> } ] } ]);
...
function App() { return <RouterProvider router={routers} />; }