can we pass a value when we move to next component

2020-07-30 03:13发布

I want to send Task_id to the ShowRecommendation.js component

  recommend = Task_id => {
        this.props.history.push("/ShowRecommendation");
      };

How it can be done?

1条回答
做个烂人
2楼-- · 2020-07-30 03:39

With react-router you can transfer "state"

this.props.history.push({
  pathname: '/ShowRecommendation',
  state: { taskid: Task_id }
})

and at the ShowRecommendation.js componenet you can get the value using

console.log(this.props.location.state)

Comment if you have more questions

查看更多
登录 后发表回答