14

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

Majid NWL
  • 317
  • 2
  • 3
  • 11
  • can you please show the code in question? And describe a bit more about what you are trying to do? – Chaim Friedman Mar 07 '18 at 16:50
  • What is your question? If you want to get rid of the message, the error says it all. You are pushing a route that leads to the same place you are currently in. – nbkhope Mar 07 '18 at 17:44
  • Could you please explain why you are navigating to the same path? That's what is usually done by reloading. – Sulthan Jul 12 '18 at 07:26
  • I think your trying to push same url path in . Try to push different path in tag. – Sagar Jul 12 '18 at 07:29

3 Answers3

24

Use Replace

add 'replace' to the NavLink or Link

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

or

<Link to="/myProfile" replace />
Omer
  • 3,232
  • 1
  • 19
  • 19
5

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

Sagar
  • 4,473
  • 3
  • 32
  • 37
0

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

before message:

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

fixed to:

    const routing = () => (
      <Switch>
        ...
      </Switch>
    );
Pablo
  • 586
  • 5
  • 14