Use replace instead of push on <Link> click when location is the same
See original GitHub issueEach time you click a <Link/>, it pushes to the browser history even if the location already matches. This differs from the default implementation of anchor tags as far as I can tell.
When a simple anchor tag is clicked 100 times, there is only one history entry
<a href="/foo">Go to Foo</a>
If you did the same for <Link />, you have 100 history entries which makes back and forward button navigation difficult.
Proposing we don’t push when the location already matches
Issue Analytics
- State:
- Created 6 years ago
- Reactions:36
- Comments:28 (10 by maintainers)
Top Results From Across the Web
What is the trade off between history push and replace?
replace acts like router. push, the only difference is that it navigates without pushing a new history entry, as its name suggests -...
Read more >location.replace() and location.assign() - Bambielli's Blog
When using react-router's history API, history.push() acts like location.assign() and history.replace() acts like, you guessed it, location.
Read more >Main Concepts v6.6.1 - React Router
A replace is similar except it replaces the current entry on the stack instead of pushing a new one. Finally, a pop happens...
Read more >location.replace() - Web APIs - MDN Web Docs
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the ...
Read more >How React Hooks can replace React Router - LogRocket Blog
Instead, we are going to explore other possibilities and look at how we can improve the routing experience in React apps using Hooks....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@timdorr actually, normal same page
<a>links don’t create duplicates, so current<Link />behavior is wrong and differs from 99% of websites. Even RR3 was working correctly, only RR4 is not.@pnest this is a problem because it differs from default behavior, you have to reinvent
Linkcomponent in every project because of RR4 (and history v4) bug.This is a really annoying bug in RR4.
Edit: I have seen the abundance of thumbs downs and acknowledge my stupidity here. Feel free to ignore this comment…
@pnest has the right idea. This is “fixable” with the replace prop.
The point of
<Link>is to emulate<a>. A normal<a>that links to the same page you are already on will push new history entities to the stack. For instance, click the react-router link at the top of the page a bunch of times. You’ll see that you have to click back multiple times to get back to this page. We want to maintain HTML semantics with our defaults, rather than reinvent them.