Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
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

@TheoMer

Description

@TheoMer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions