navi
navi copied to clipboard
Same link creates duplicates in location history
Hey,
When clicking same link, it creates duplicates in history so when you click back, you get to the same page.
Tested on basic example.
Click home -> about -> about -> about -> back
. You would expect to go back to home, but you will stay on the same page. Default browser <a>
tag doesn't create same page history duplicates.
This is a well know bug in history package (since v4) which was reported multiple times in react-router (RR#5500, check number of linked issues) and in history (H#507).
React-router guys tell this should be fixed in history while history guy one day tells it should be fixed in react-router, next day says it should fixed in history and wants a pr, next day closes pr with no comments (H#570).
Maybe at least one router will have links that work same way as browser ones.
So personally, I'd say this isn't a bug in history, but I do agree that it would be nice to solve it within the router. The reason I'd say that it isn't a bug in history is because this is how the browser's window.history
works, and the history package should act as a thin wrapper around it.
The way to implement this I think is to add a condition to navigation.navigate()
, that returns without navigating if all of the following conditions are true:
- The new URL matches the existing URL
- The existing URL has an empty
state
or nostate
object - The new URL has an empty
state
object or nostate
object
Would be happy to accept a PR for this.