【问题标题】:How to make `goBack()` method of history to ignore hash (#)?如何使历史的`goBack()`方法忽略哈希(#)?
【发布时间】:2020-01-07 16:11:58
【问题描述】:

我有一些使用/routename#somefilter 的路由。这不是一条完全不同的路线,它只是我们使用的一个过滤器标志。

但是,每当我访问/routename#somefilter 并单击应用程序中的后退按钮时,它会返回到/routename,而不是实际的先前路线(例如,我来自/anotherroutename,然后转到/routename)。

如何让 react-router 中的 history 忽略哈希路由?顺便说一句,我正在使用useHistory() 钩子。

【问题讨论】:

  • 你是在使用history.push在url中添加吗?
  • @AmitChauhan 是的,使用 push 将 # 添加到路径中..

标签: reactjs react-router


【解决方案1】:

不要使用history.push,而是使用history.replace 来更新网址。 history.push 将新条目添加到路由器历史记录中,因此如果您使用 history.replace,则为历史记录中的当前条目。

【讨论】:

    猜你喜欢
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 2020-12-05
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多