React Router:替换位置状态,然后返回,位置状态未定义

问题描述 投票:0回答:1
this.props.history.replace({
  state: {
    from: 'dashboard'
  }
});

this.props.history.goBack();

this.props.location.state的值在更新undefined后使用this.props.history.goBack()时为this.props.location.state。但是

this.props.history.push({
  pathname: '/',
  state: {
    from: 'dashboard'
  }
});

工作并保留this.props.location.state的值。

知道如何更新this.props.location.state然后使用this.props.history.goBack吗?

reactjs react-router browser-history
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.