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.
willTransferFrom
in a route handler can be used to catch transitions and abort them if the user does not actually want to leave the page. When this transition is caused by using the forward and backwards buttons in the browser, react router has to undo this. Currently it does it by usingHistory.back()
which is problematic when the browser has already gone back. Instead it needs to go forward or redirect back to the original page.This issue is documented in the original repo in issues like this one: remix-run/react-router#1613. The react training team later solved by releasing version 1.0.0, which besides other major changes also uses the
history
dependency.This PR is for https://github.com/meadow/admin/pull/731/commits/57cdb6179b4917c4394eda9be95608b68000cd09
PR meadow/admin#731 does not need to be updated on merge as meadow/admin#731 is pointing to a version tag.
The solution implemented here adds an extra meta property containing previous route location (ie current after the user clicks back) to the transition object. This allows the listener for route changes in the object to use the meta to redirect back to the original page, instead of relying on abort which calls
History.back
. Abort is still used when the action causing the transition is not apop
. Going backwards or forwards is apop
action whereas click a link is apush
action.