React Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history

Posted ostrich-sunshine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history 相关的知识,希望对你有一定的参考价值。

      前言:

  • react-router-dom 4.4.2  

在页面中直接使用

import { Link } from react-router-dom
//使用
<Link to={{ pathname: "/app/studyMapModule/detail" }} >detail</Link> 
可能报错:
browser.js?fec5:49 Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack
技术分享图片

原因:浏览器不会将同样的路径 push 到 stack 里

解决:添加上replace
<Link to={{ pathname: "/app/studyMapModule/detail" }} replace>detail</Link> 

 

参考:https://github.com/ReactTraining/history/issues/488

以上是关于React Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history 的主要内容,如果未能解决你的问题,请参考以下文章

hash history cannot push state it is ignored

react 对循环warning提示增加key的研究

从一个warning入手----熟悉React生命周期

从一个warning入手----熟悉React生命周期

解决react: Warning:componentWillMount has been renamed 问题

vscode写react有warning