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

猜你喜欢

转载自www.cnblogs.com/ostrich-sunshine/p/9770774.html