Switch component incorrectly matching routes
See original GitHub issueHi there, I don’t think the <Switch> component is matching correctly, or at least I’m not using it correctly.
<Switch>
<Route exact path="/" component={Home} />
<About />
<Route component={Splat} />
</Switch>
The <About /> component contains its own routes:
<div>
<Route path="/foo/one" component={One} />
<Route path="/bar/two" component={Two} />
</div>
With this setup, I’m never able to render the Splat route since it thinks About is a match.
This codepen should illustrate my issue - https://codepen.io/justinpincar/pen/xrqQEZ
https://stackoverflow.com/questions/44642711/react-router-v4-catch-all-route
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Switch component incorrectly matching routes #5261 - GitHub
With this setup, I'm never able to render the Splat route since it thinks About is a match. This codepen should illustrate my...
Read more >React Router Switch routes not being matched - Stack Overflow
First I have a Switch component with several children Route components (as shown below) and everything routes as expected. Paths that do not ......
Read more >Using Switch and React-Router to create a catch-all 404 ...
Switch attempts to match a URL path from the top-most Route path to the bottom-most Route path. It renders the component for the...
Read more >Why switch keyword used in React Router v4 ? - GeeksforGeeks
The route matching is done in a way that if a part of this relative URL is matched then that Route is rendered....
Read more ><Switch> and exact - Learn React Router - Codecademy
By design, a Router will render all the Routes whose paths match the current URL. This allows us to compose layouts in which...
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

I’m having trouble with this, if I extend the
Routeinto aAboutRoutedoes<Switch />treat it the same? I’ve found my custom<AboutRoute />'s are always rendered.@AlastairTaft I’m seeing the same issue. Honestly, I’ve even tried throwing in a random UI component into the switch with the
pathproperty and it appears to be matching it too.