I have the start page in the Root component and I added the Header and Footer components wrapped in a div, but I don't know how to include them with the rest of the routes in the best way. Am I missing something or using the wrong approach?
Moreover, I am using createBrowserRouter instead of BrowserRouter since I am using data APIs as mentioned in the docs Picking a Router
Here is my code:
const router = createBrowserRouter([
{
path: '/',
element: (
<div>
<Header />
<Root />
<Footer />
</div>
),
errorElement: <ErrorPage />,
},
{
path: '/products',
element: <ProductsList />,
},
{
path: '/products/:productId',
element: <SingleProductPage />,
},
])
const root = ReactDOM.createRoot(document.getElementById('app'))
root.render(
<React.StrictMode>
<Provider store={store}>
<RouterProvider router={router} />
</Provider>
</React.StrictMode>
When I navigate to '/' the Header and Footer displays, but that's not the case for other routes.