Fix Matched leaf route at location not have an element in React router
In this tutorial, we are going to learn about how to fix the Matched leaf route at location ”/” does not have an element in React router.
When we try to create a route in react router v6 using the following syntax.
<Route path="/posts" component={Posts}/>
We will see the following error in our console:
Matched leaf route at location "/" does not have an element.
This means it will render an <Outlet />
with a null value by default resulting in an "empty" page.
This error occurs due the usage of component
prop in Route component, which is not available in react router v6. To fix this error, we need to use the element
prop instead of a component prop.
Here is an example:
<Route path="/posts" element={<Posts/>}/>