reactjs - 有没有办法让我可以访问浏览器历史记录中的所有项目或至少历史的顶部项目
问题描述
我有一个场景,我必须在提交表单时采取一些行动。
我从两条途径得出这种特殊形式。比方说 /first-route 和 /second-route
现在我的目标很简单,如果我来自 /first-route,我必须在提交表单时返回 /first-route。但如果我来自 /second-route 或其他任何地方,我必须去 /third-route。
有没有办法访问 react-router 历史对象中的最后一项,以便我可以有条件地进行此路由。
该功能history.goBack()
将我带回最后一条路线,但我想要的是在返回之前先检查这条路线
如果路线是 /first-route 我想做的history.push('/first-route')
。在其他情况下我必须这样做history.push('/third-route')
。
此外,对于更多上下文,我有两个独立的反应应用程序,必须在它们之间进行这种通信。
我有两个应用程序嵌入在第三个应用程序中。我想让父应用程序独立于这种通信。
解决方案
属性 每个历史对象都具有以下属性:
history.length - The number of entries in the history stack
history.location - The current location (see below)
history.action - The current navigation action (see below)
此外,createMemoryHistory 提供了 history.index 和 history.entries 属性,可让您检查历史堆栈。
推荐阅读
- reactjs - 我将一个函数移到了课堂之外并制作了 const。现在该功能不起作用
- lucene - DotNetNuke Lucene 搜索在负载平衡环境中不起作用“锁定获取超时”,如何解决?
- html - 使用 HTML 表单提交 JSON 对象数组
- rxjs - 路由器重定向后订阅调用次数过多
- vhdl - 用于 fpga 模拟的 Active-hdl 中的 MachX03 库错误
- azure-resource-manager - 无法在当前资源组中创建请求的应用服务计划,因为它正在托管 Linux 应用
- c - 切换数组中的两个元素
- mysql - 无法创建 mysql 表:外键约束问题
- solr - Solr 在查询结果中返回页面内容_text_
- javascript - ajax,当它具有不同的值时,我得到相同的值