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.

Route not sending correct Match object as prop

See original GitHub issue

Hello!

In attempting to use path params, I’m encountering an issue where the state of the <Route> shows the correct match object (with the correct path, params object) but a different match object is being passed to the render prop function. So here’s some sample code:

class App extends Component {
  render() {
    return (
      <div>
        <Switch>
          <Route exact path="/" render={props => <Home {...props} {...this.props} />} />
          <Route exact path="/users" render={props => <Users {...props} {...this.props} />} />
          <Route exact path="/users/new" render={props => <NewUser {...props} {...this.props} />} />
          <Route path="/users/:id" render={props => <User {...props} {...this.props} />} />
        </Switch>
      </div>
    )
  }
}

And some screenshots from dev tools to show you what I mean:

image

The User component, which should be getting the same match object from the above state as a prop: image

Also note that for some reason isExact is true on the Route’s state when it should be false. Am I doing something wrong, or is this a bug of some sort? Using react-router[-dom]@4.1.1 and it’s under a react-router-redux <ConnectedRouter /> but I don’t think that’s the cause.

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

16reactions
danvoycecommented, Oct 31, 2017

Be great if you could update your findings on here 😃

0reactions
mcmundercommented, Jun 15, 2018

Any news on this? Having the same problem here…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Route not sending correct Match object as prop #5169 - GitHub
Hello! In attempting to use path params, I'm encountering an issue where the state of the shows the correct match object (with the...
Read more >
React Router don't pass value to match.props - Stack Overflow
I want to use the match object to find the props in a given url, so I can do this: function NumberHeader ({match}){...
Read more >
Match - React Router: Declarative Routing for React.js
A match object contains information about how a <Route path> matched the URL. match objects contain the following properties: params - (object) Key/value...
Read more >
Route - Angular
A set of routes are collected in a Routes array to define a Router configuration. The router attempts to match segments of a...
Read more >
React Router v5: The Complete Guide - SitePoint
Ideally, a <Route> component should have a prop named path , and if the path name matches the current location, it gets rendered....
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