当我们使用this.props.history.push(“ / next Component”)移动到下一个组件时,我们可以传递一个值吗?

问题描述 投票:1回答:1

我想将Task_id发送到ShowRecommendation.js组件

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

如何完成?

javascript reactjs routing url-routing react-props
1个回答
1
投票

使用react-router,您可以传送“状态”

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

并且在ShowRecommendation.js componenet上,您可以使用]来获得价值>

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

如果有更多问题,请评论

© www.soinside.com 2019 - 2024. All rights reserved.