方式:通过
this.props.history.push的方式进入另一个组件,通过隐式传递;也可以通过query显式传递
方式一
当前组件通过路由传递一个state
productDetail = () =>{
const data = [
'Racing car sprays burning fuel into crowd.',
'Japanese princess to wed commoner.',
'Australian walks 100km after outback crash.',
'Man charged over missing wedding girl.',
'Los Angeles battles huge wildfires.',
];
this.props.history.push({ pathname:'/product/detail',state:data})
}
目标组件通过state进行获取
const data=this.props.location.state
方式二
传递
const data = {}
this.props.history.push({ pathname:'/product/detail',query:data})
获取
const data = this.props.location.query

本文详细介绍了在React中使用props.history.push方法进行组件间跳转并传递参数的两种方式:一是通过state传递,二是在query中传递。通过具体代码示例,展示了如何在源组件中设置参数,并在目标组件中获取这些参数。
1281

被折叠的 条评论
为什么被折叠?



