【问题标题】:how to use data that are sent by this.props.history?如何使用 this.props.history 发送的数据?
【发布时间】: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


【解决方案1】:

您可以发送来自路由器的名为 state 的道具:

this.props.history.push({
 pathname: '/postDetail',
 state: { data: item }
});

所以现在你的组件附加到该路由将具有可用的位置属性,在位置对象内是你传递的状态。 更多信息在这里:https://reacttraining.com/react-router/web/api/history

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2011-04-19
    • 2016-12-12
    • 2022-01-03
    • 2019-09-18
    • 1970-01-01
    相关资源
    最近更新 更多