Categories
React Answers

How to fix ‘Matched leaf route at location “/” does not have an element’ error with React Router 6?

Spread the love

To fix ‘Matched leaf route at location "/" does not have an element’ error with React Router 6, we set the element prop to the component we want to render when we go to the URL.

For instance, we write

<Route path="/" element={<Home />}></Route>;

to add a Route component with the element prop set to the Home component.

Then when we go to /, we see the Home component rendered.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *