【发布时间】:2020-06-27 17:38:48
【问题描述】:
当我想使用 this.props.history.push("/") 从一条路线转到另一条路线时,我还想发送一些额外的数据,例如:this .props.history.push('/postDetail', {data: item})。但是我不知道在我们去的类中如何定义这些数据。
提前谢谢你
【问题讨论】:
标签: javascript reactjs redux react-redux react-router-dom
当我想使用 this.props.history.push("/") 从一条路线转到另一条路线时,我还想发送一些额外的数据,例如:this .props.history.push('/postDetail', {data: item})。但是我不知道在我们去的类中如何定义这些数据。
提前谢谢你
【问题讨论】:
标签: javascript reactjs redux react-redux react-router-dom
您可以发送来自路由器的名为 state 的道具:
this.props.history.push({
pathname: '/postDetail',
state: { data: item }
});
所以现在你的组件附加到该路由将具有可用的位置属性,在位置对象内是你传递的状态。 更多信息在这里:https://reacttraining.com/react-router/web/api/history
【讨论】: