当我们使用this.props.history.push(“ / next Component”)移到下一个组件时,我们可以传递一个值吗? [英] can we pass a value when we move to next component using this.props.history.push("/next Component")?
本文介绍了当我们使用this.props.history.push(“ / next Component”)移到下一个组件时,我们可以传递一个值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 Task_id 发送到 ShowRecommendation.js 组件
recommend = Task_id => {
this.props.history.push("/ShowRecommendation");
};
如何完成?
推荐答案
使用react-router,您可以传输状态
With react-router you can transfer "state"
this.props.history.push({
pathname: '/ShowRecommendation',
state: { taskid: Task_id }
})
,并在ShowRecommendation.js组件上,您可以使用
and at the ShowRecommendation.js componenet you can get the value using
console.log(this.props.location.state)
如果您有更多疑问,请评论
Comment if you have more questions
这篇关于当我们使用this.props.history.push(“ / next Component”)移到下一个组件时,我们可以传递一个值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文