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

ぐ巨炮叔叔 提交于 2020-04-15 21:58:11

问题


I'm working on react-router-dom and in console this error is appearing.

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


回答1:


Basically, the problem is that if you are on page /here and click a link to /here, you end up with essentially duplicate (just different keys) location objects. Please confirm that your pushing the different paths in <Link to='/diff'/>

checkout this link for more reference: https://github.com/ReactTraining/react-router/issues/5996




回答2:


Use Replace

add 'replace' to the NavLink or Link

<NavLink exact to="/myProfile" replace >My Propile</NavLink>

or

<Link to="/myProfile" replace />



回答3:


I got this message. I change the routing variable to function

before message:

    const routing = (
      <Switch>
        ...
      </Switch>
    );

fixed to:

    const routing = () => (
      <Switch>
        ...
      </Switch>
    );


来源:https://stackoverflow.com/questions/49157214/warning-hash-history-cannot-push-the-same-path-a-new-entry-will-not-be-added-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!