Error: A Route is only ever to be used as the child of Routes element

Error: A Route is only ever to be used as the child of Routes element

Posted by Margie Crona on June 15, 2022

Error: A Route is only ever to be used as the child of Routes element

Error: A Route is only ever to be used as the child of Routes element

Posted by Margie Crona on June 15, 2022

If you ever come across this error in your React project:

Error: A  is only ever to be used as the child of  element

Your project has react-router-dom version 6. In version 6, you will need to wrap all Route components into a Routes component.. 

Here is an example:


   }/>
   }/>
   }/>

However, you can always revert to version 5.

That is it!

This field is required
Your question have been successfully submitted and will be reviewed before published
Please login to ask a question