How to pass params with history.push/Link/Redirect in react-router v4?

前端 未结 10 912
你的背包
你的背包 2020-11-22 04:27

How can we pass parameter with this.props.history.push(\'/page\') in React-Router v4?

.then(response => {
       var r = this;
        if (re         


        
10条回答
  •  清酒与你
    2020-11-22 04:55

    If you need to pass URL params

    theres a great post explanation by Tyler McGinnis on his site, Link to the post

    here are code examples:

    1. on the history.push component:

      this.props.history.push(`/home:${this.state.userID}`)

    2. on the router component you define the route:

    3. on the Home component:

    componentDidMount(){
        const { myKey } = this.props.match.params
        console.log(myKey )
    }
    

提交回复
热议问题