带有修改的URL的goBack()

问题描述 投票:0回答:1

我有一个绑定了事件的按钮,使用户可以使用react-router-redux goBack()函数返回到上一页。

handleBackClick() {
    this.props.dispatch(goBack());
}

假设上一个链接为:

https://mysite.fake/something?someParam=4&another=12

并且当前链接类似于:

https://mysite.fake/test1?p1=true&p2=Banana

从当前链接,我想回到上一个链接,但删除一些参数,以便可以转到:

https://mysite.fake/something?another=12

如何获得上一个链接,删除一些参数并重定向到它?

reactjs react-router react-router-redux
1个回答
0
投票

使用纯JavaScript获取历史记录:

function goBack() {
  let next = window.history.back()
  next = next.replace('someParam=4&','');
}

然后替换您要删除的内容。

© www.soinside.com 2019 - 2024. All rights reserved.