react-router-dom 组件之间跳转传递参数

mac2026-01-22  5

方式:通过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
最新回复(0)