question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch component incorrectly matching routes

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AlastairTaftcommented, Jul 4, 2017

I’m having trouble with this, if I extend the Route into a AboutRoute does <Switch /> treat it the same? I’ve found my custom <AboutRoute />'s are always rendered.

0reactions
ceriveracommented, Nov 2, 2018

@AlastairTaft I’m seeing the same issue. Honestly, I’ve even tried throwing in a random UI component into the switch with the path property and it appears to be matching it too.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found