【问题标题】:Is there a method to change the URL without reloading or making changes to the history?有没有一种方法可以在不重新加载或更改历史记录的情况下更改 URL?
【发布时间】:2018-04-20 13:46:08
【问题描述】:

我有一个反应应用程序,用户单击一个按钮,然后返回一个随机项目,我想从该项目中取出一个属性并将其附加到 URL。但是,我不希望页面重新加载。虽然我可以使用 history.replace / history.push 更新 URL,但问题是如果用户点击返回,那么他们将返回到最后一页,该页面根据 redux-store 中的先前值正确呈现,但 URL 会滞后。

例如,如果用户在 myapp/item6 上并点击后退按钮,他们将返回到 myapp/item5,但 URL 不会更改以反映这一点。

目前,使用 react-router 和 withRouter。

【问题讨论】:

    标签: javascript reactjs redux react-router history


    【解决方案1】:
    <Link 
      to={{ 
        pathname: '/somelocation',
        state: { from: props.location } 
      }}
    />
    

    然后在你的后退按钮中

    <Link to={props.location.state.from}>
      Back
    </Link>
    

    【讨论】:

      猜你喜欢
      • 2014-01-23
      • 2015-11-15
      • 2019-09-30
      • 2012-08-27
      • 2014-01-10
      • 2020-10-04
      • 2011-01-02
      • 2014-03-13
      相关资源
      最近更新 更多