-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use replace instead of push on <Link> click when location is the same #5362
Comments
Same issue |
Is it an issue? You can check link yorself and set appropriate 'replace' attribiute value in |
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 |
@timdorr I actually think that the behavior of that link is caused by GitHub's SPA working incorrectly. Quoting myself from here:
Using the Since this is a history issue, this doesn't need to be reopened. If/when history is updated to add same location detection, the |
@timdorr actually, normal same page @pnest this is a problem because it differs from default behavior, you have to reinvent This is a really annoying bug in RR4. |
Re-opening this issue because this is still broken. Going to add this to the roadmap for our next minor release. |
I think that there could be a temp fix in a minor release of React Router, but the best long term approach would be for |
You want to fix this in react-router, okay. But is there maybe a path for other libraries that have have a concept of showing screens (like modals) to also integrate programatically with the same history stack that react-router uses? Something along the lines of: import { RouterAPI } from "react-router-dom";
// optional
const options = {
replace: false,
// ...
}
RouterAPI.go('...', options);
RouterAPI.link('...', options);
RouterAPI.navigate('...', options);
RouterAPI.emitLinkClick('...', options);
RouterAPI.immitateLinkClick('...', options); |
@guidobouman React Router uses the |
@pshrmn I know. I have built this functionality on top of |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@mjackson If this is the tracking ticket for this feature I would like to prevent this from becoming stale. Any ETA on 5.2? |
@guidobouman @mjackson maybe we could consider updating |
I just use function applyBrowserLocationBlocker(history: History) {
let currentLocation = null
history.block((location, action) => {
const nextLocation = location.pathname + location.search
if (action === 'PUSH') {
if (currentLocation === nextLocation) {
return false
}
}
currentLocation = nextLocation
})
} |
I'm with @guidobouman I thought that was the intent of not completely owning the history responsibility, exposing historys state. I do agree that non-state changing reloads of the same page route should be consolidated if at all automatable, atleast with a flag to use replace for those that want their hands off the navigation completely. The logic could live safely in Link to verify before dispatching. |
I want to be clear I am satisfied with this behavior and would prefer any changes to be behind a flag rather than having to lock at version, are there any others seeing the current behavior as a feature rather than a bug? This package was a life saver and it deserves appriciation. I love the conversations I see over here. Keep up the great work! |
1431: fix: update react monorepo to v17.0.2 (master) r=renovate[bot] a=renovate[bot] [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react](https://reactjs.org/) ([source](https://togithub.com/facebook/react)) | [`17.0.1` -> `17.0.2`](https://renovatebot.com/diffs/npm/react/17.0.1/17.0.2) | [![age](https://badges.renovateapi.com/packages/npm/react/17.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react/17.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react/17.0.2/compatibility-slim/17.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react/17.0.2/confidence-slim/17.0.1)](https://docs.renovatebot.com/merge-confidence/) | | [react-dom](https://reactjs.org/) ([source](https://togithub.com/facebook/react)) | [`17.0.1` -> `17.0.2`](https://renovatebot.com/diffs/npm/react-dom/17.0.1/17.0.2) | [![age](https://badges.renovateapi.com/packages/npm/react-dom/17.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-dom/17.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-dom/17.0.2/compatibility-slim/17.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-dom/17.0.2/confidence-slim/17.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>facebook/react</summary> ### [`v17.0.2`](https://togithub.com/facebook/react/blob/master/CHANGELOG.md#​1702-March-22-2021) [Compare Source](https://togithub.com/facebook/react/compare/v17.0.1...v17.0.2) ##### React DOM - Remove an unused dependency to address the [`SharedArrayBuffer` cross-origin isolation warning](https://developer.chrome.com/blog/enabling-shared-array-buffer/). ([`@​koba04](https://togithub.com/koba04)` and [`@​bvaughn](https://togithub.com/bvaughn)` in [#​20831](https://togithub.com/facebook/react/pull/20831), [#​20832](https://togithub.com/facebook/react/pull/20832), and [#​20840](https://togithub.com/facebook/react/pull/20840)) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/foosbyte/kicker-trainer). 1432: fix: update react-router monorepo (master) r=renovate[bot] a=renovate[bot] [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-router](https://togithub.com/ReactTraining/react-router) | [`5.2.0` -> `5.2.1`](https://renovatebot.com/diffs/npm/react-router/5.2.0/5.2.1) | [![age](https://badges.renovateapi.com/packages/npm/react-router/5.2.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-router/5.2.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-router/5.2.1/compatibility-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-router/5.2.1/confidence-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | | [react-router-dom](https://togithub.com/ReactTraining/react-router) | [`5.2.0` -> `5.3.0`](https://renovatebot.com/diffs/npm/react-router-dom/5.2.0/5.3.0) | [![age](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.0/compatibility-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.0/confidence-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>ReactTraining/react-router</summary> ### [`v5.2.1`](https://togithub.com/ReactTraining/react-router/releases/v5.2.1) [Compare Source](https://togithub.com/ReactTraining/react-router/compare/v5.2.0...v5.2.1) This release fixes a bug with `<Link>` so that, when the `to` location is the same as the current, the history state entry is replaced instead of pushed to the stack. See [https://github.com/remix-run/react-router/issues/5362](https://togithub.com/remix-run/react-router/issues/5362) for details. 🥳 Thanks to [`@​guidobouman](https://togithub.com/guidobouman)` for the PR and for everyone else who weighed in for the fix! </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/foosbyte/kicker-trainer). Co-authored-by: Renovate Bot <bot@renovateapp.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-router](https://togithub.com/remix-run/react-router) | [`5.2.0` -> `5.3.4`](https://renovatebot.com/diffs/npm/react-router/5.2.0/5.3.4) | [![age](https://badges.renovateapi.com/packages/npm/react-router/5.3.4/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-router/5.3.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-router/5.3.4/compatibility-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-router/5.3.4/confidence-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | | [react-router-dom](https://togithub.com/remix-run/react-router) | [`5.2.0` -> `5.3.4`](https://renovatebot.com/diffs/npm/react-router-dom/5.2.0/5.3.4) | [![age](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.4/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.4/compatibility-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-router-dom/5.3.4/confidence-slim/5.2.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>remix-run/react-router (react-router)</summary> ### [`v5.3.4`](https://togithub.com/remix-run/react-router/releases/tag/v5.3.4) [Compare Source](https://togithub.com/remix-run/react-router/compare/v5.3.3...v5.3.4) We removed the `mini-create-react-context` dependency, moving it into an internal module to eliminate peer dependency warnings for users on React 18 ([#​9382](https://togithub.com/remix-run/react-router/issues/9382)). **Full Changelog**: remix-run/react-router@v5.3.3...v5.3.4 ### [`v5.3.3`](https://togithub.com/remix-run/react-router/releases/tag/v5.3.3) [Compare Source](https://togithub.com/remix-run/react-router/compare/v5.3.2...v5.3.3) This release fixes a bad version selector in react-router-native. ### [`v5.3.2`](https://togithub.com/remix-run/react-router/releases/tag/v5.3.2) [Compare Source](https://togithub.com/remix-run/react-router/compare/v5.3.1...v5.3.2) - Fix: make v5 Router compatible with v18 StrictMode by [@​jgoz](https://togithub.com/jgoz) in [https://github.com/remix-run/react-router/pull/8831](https://togithub.com/remix-run/react-router/pull/8831) ### [`v5.3.1`](https://togithub.com/remix-run/react-router/releases/tag/v5.3.1) [Compare Source](https://togithub.com/remix-run/react-router/compare/v5.2.1...v5.3.1) This release adds missing `LICENSE` files to the published build. ### [`v5.2.1`](https://togithub.com/remix-run/react-router/releases/tag/v5.2.1) [Compare Source](https://togithub.com/remix-run/react-router/compare/v5.2.0...v5.2.1) This release fixes a bug with `<Link>` so that, when the `to` location is the same as the current, the history state entry is replaced instead of pushed to the stack. See [https://github.com/remix-run/react-router/issues/5362](https://togithub.com/remix-run/react-router/issues/5362) for details. 🥳 Thanks to [@​guidobouman](https://togithub.com/guidobouman) for the PR and for everyone else who weighed in for the fix! </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/sullivanpj/open-system).
Each 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
The text was updated successfully, but these errors were encountered: