Skip to content
Advertisement

Navigate through child routes using react-router-dom V6

I am using react-router-dom V6 both Routes and useRoute, So, in the site, the main routes are as follow:

JavaScript

As see above the second Route’s element is <AdminApp /> this element is coming from the following:

JavaScript

So whenever i call the route /admin nothing display in the screen and in the console log I am getting this warning

JavaScript

I have changed <Route path="admin" element={<AdminApp />} /> to <Route path="admin/*" element={<AdminApp />} /> so the warning disappeared but the page displays blank when i navigate to the route admin/ and it replace admin word with dashboard in the url:

what happened:

JavaScript

what expected:

JavaScript

Advertisement

Answer

I have replaced ‘/’ in first child route to ” and it worked for me. something like this :

JavaScript

Here is simple app working example

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement