react-router-config does not match on later paths even if there is an exact path match later
See original GitHub issueVersion
4.1.1
Test Case
None
Steps to reproduce
Create a react-router-config that has the following:
[{ component: someAuthorizedLayout
routes: [
{component: AuthorizedDashboard, path: '/home, exact: true}
]
},
{ component: UnauthorizedLayout
routes: [
{component: Login, path: '/', exact: true}
]
}]
Try to go to ‘/’ and you are unable to. Why? Because the route matches the first route and “consumes” the request before it realizes that there is a ‘/’ exact match
Expected Behavior
I expect it to go to the Login page.
Actual Behavior
It goes to no route because it traverses the routes tree and when it hits someAuthorizedLayout it finds no nested routes that match.
Is this a bug? or is this by design?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
react-router-config does not match on later paths even if there ...
It goes to no route because it traverses the routes tree and when it hits someAuthorizedLayout it finds no nested routes that match....
Read more >react-router render menu when path does not match
It will only run the first matching Route and routes without a path attribute match anything. <div> <Switch> <Route exact path="/" render={props ...
Read more >Match - React Router: Declarative Routing for React.js
A <Route> that uses the children prop will call its children function even when the route's path does not match the current location....
Read more >React Router - Testing Library
This example demonstrates React Router v6. For previous versions see below. // app.js import React from 'react' import {Link, Route, Routes, ...
Read more >ReactJS | Router - GeeksforGeeks
1.exact: It is used to match the exact value with the URL. For Eg., exact path='/about' will only render the component if it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This does appear to be a bug in rrc. We’re not doing any testing of that form of routes, so the first step would be to add a failing test. Then we can go about fixing for it.
Edit: Why are people thumbs-downing me? 😭
I believe
renderRoutesshould not be using a<Switch>internally, but rather should return an array of<Route>elements.