Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

HowTo: Access props.params in react-router v4 #319

Closed
TheoMer opened this issue Jun 12, 2017 · 1 comment
Closed

HowTo: Access props.params in react-router v4 #319

TheoMer opened this issue Jun 12, 2017 · 1 comment

Comments

@TheoMer
Copy link

TheoMer commented Jun 12, 2017

OS: Windows 10 Pro
React-router: 4.1.1
React: 15.5.4

So, I have recently updated my react-router v2 to v4 and cannot now access props.params.

My routing is as follows:

  render () {
    console.log('props.children = ', this.props.children);
    console.log('props = ', this.props);
    return (
      <div>
        <h1>
          <Link to="/">Flamingo City</Link>
        </h1>
        <Switch>
          <Route path={`${this.props.match.url}view/:postId`} render={() => (
            <Single {...this.props.children} {...this.props} />
            )} />
        </Switch>
      </div>
    );
  }

So attempting to do the following in Single.js now throws an undefined error message:

const postId = this.props.params.postId;

How do I resolve this?

@TheoMer
Copy link
Author

TheoMer commented Jun 12, 2017

The issue was resoved by doing the following:

          <Route path={`${this.props.match.url}view/:postId`} render={(props) => (
            <Single {...this.props} {...props} />
            )} />

@TheoMer TheoMer closed this as completed Jun 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant