React Router v4 params

Viewed 1052

I'm following a React tutorial that is using React Router v3. While I'm using React Router v4. I'm passing a parameter called id from a component called Root to another component called User.

export class Root extends  React.Component {
    render() {
        return(
            <div className="container">
                <div className="row">
                    <div className="col-xs-10 col-xs-offset-1">
                        <Header />
                    </div>
                </div>
                <div className="row">
                    <div className="col-xs-10 col-xs-offset-1">
                        <hr/>
                        <Route exact path="/" component={Home}/>
                        <Route path="/user/:id" component={User}/>
                        <Route path="/home" component={Home}/>
                        {/*{this.props.children}*/}
                    </div>
                </div>
            </div>
        );
    }
}

And I'm picking up the parameter with {this.props.match.params.id} like below and works.

export class User extends React.Component {

    onNavigateHome() {
        this.props.history.push("/home")
    }

    render() {
        return (
            <div>
                <h3>The User Page</h3>
                <p>User ID: {this.props.match.params.id}</p>
                <button onClick={() => this.onNavigateHome()} className="btn btn-primary">Go home!</button>
            </div>
        );
    }
}

In the tutorial {this.props.params.id} is used. Am I doing it the right way in with {this.props.match.params.id}? And what does match mean?

1 Answers
Related