Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Using react-router's <Link/> component causes double history entries #171

Closed
kromit opened this issue Jan 6, 2016 · 3 comments
Closed

Comments

@kromit
Copy link

kromit commented Jan 6, 2016

history.push(location) is called two multiple times with the same values:

  • first time when the <Link> is clicked

  • second time when route store listener is called:

    var unsubscribeStore = store.subscribe(function () {
         var routing = getRouterState();
         // Only trigger history update if this is a new change or the
         // location has changed.
         if (lastRoute.changeId !== routing.changeId || !locationsAreEqual(lastRoute, routing)) {
    
             lastRoute = routing;  
             var method = routing.replace ? 'replaceState' : 'pushState';
             history[method](routing.state, routing.path);
         }
     }
    

This always calls history.pushState for second time because history/router and browser window already have the new location but lastRoute still contain old path. This effectively causes two equal history entries so the browser back button works on the second click only.

The current history location and window.location should be checked before history.push to prevent duplicate history entries.

@ernoaapa
Copy link

ernoaapa commented Jan 7, 2016

I have this same issue.
As a workaround, I stopped using Link and use pushPath to change current page.

@BerkeleyTrue
Copy link

@kromit Have you tried it with the new version https://github.com/rackt/redux-simple-router/blob/master/src/index.js#L99

It shouldn't have the same problem since it uses the key created by RR.

@kromit
Copy link
Author

kromit commented Jan 7, 2016

2.0.1 fixed it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants