我目前正在传递路由更改的状态,如下所示:
View Details我的逻辑是,如果"location.state.transaction“存在,则不获取新数据,否则,获取数据。
现在的缺陷是当页面重新加载时。如果用户重新加载页面,应用程序需要获取新数据。我以为如果重新加载,"location.state“就会被清除,但很明显,这个状态是保存在sessionStorage中的。
我该如何解决这个问题呢?我可以每次都获取新数据,但它不应该在单击“View Details”链接时获取数据。
发布于 2019-06-02 20:31:18
有一种更好的方法,不用使用三方库。
我们可以使用history.replace()
https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md
componentDidMount(){
const {location,history} = this.props;
//use the state via location.state
//and replace the state via
history.replace()
}https://stackoverflow.com/questions/40099431
复制相似问题