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

      前言:

  • 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

文章来自:https://www.cnblogs.com/ostrich-sunshine/p/9770774.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3