fix(gatsby-link): replace current path in history rather than pushing it #23414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
I'd like to start by thanking you for this awesome project.
Sorry if this contribution doesn't match the guidelines, but I hope I understood them well.
Description
This change makes
<GatsbyLink>
asknavigate
to use replaceState rather than pushState when navigating on a link that is the current page. This fixes an issue where a history item would be pushed multiple times for the current page, while this is not the expected behaviour.If a developer forced "replace" using the prop, their choice takes priority.
This uses the same technique as @reach/router when they fixed it upstream: reach/router@11e9ed6
I did not copy the
part, because I do not understand it.
I also added some tests.
Note: I did not manage to get unit tests to run on my computer (either by using Node 10, 12, 13 or 14, or even trying on all 3 operating systems). They didn't work in the linked gitpod either.
That said, I tested the changes in gatsby-link using
yarn jest
in its folder.Documentation
I don't believe this needs documentation other than updating the changelog
Related Issues
Fixes #22124