You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 35281e5
Browse filesBrowse the repository at this point in the historyBrowse files
fix(react-router): keep pages in back history mounted after a replace (#31827)
Issue number: resolves#31815
---------
<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->
<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->
## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->
Currently, a replace to a sibling route unmounts every sibling page in
the outlet, including the page that pushed the one being replaced. Going
back remounts that page, so its state is lost and swipe back can't
start. A redirect through `<Navigate replace>` unmounts the page behind
it the same way.
## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->
A replace now only unmounts the page it replaces. Before the outlet
removes any other view, it checks the location history and keeps every
view that back can still reach, which matches React Router since a
replace only swaps one history entry. When the leaving view is a
redirect with no page of its own, we transition out the page that was
showing before it, and unmount that page only once it's out of history.
## Does this introduce a breaking change?
- [ ] Yes
- [X] No
<!--
If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->
## Other information
<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
The sibling cleanup came in with the React Router 6 migration to get rid
of root-level siblings that never unmounted. Views that are out of
history still get cleaned up, so that case still works.
The "Home with redirect" and "Home with router" routing tests now expect
Favorites to be hidden instead of removed, because it's still in the
back history. The `replace-params` test page also pops back to step 1
now, which is what its description says it does. It only worked before
because of the old cleanup.
<TestDescription>Tap "Replace to Step 2 (first)" -> "Replace to Step 3" -> "Push to Step 4" -> go back to Step 1. Then repeat with "second". On the second visit to Step 3, it should show the "second" param and a different mount ID, confirming the old view was cleaned up from the DOM (issue #25640).</TestDescription>
51
+
<TestDescription>Tap "Replace to Step 2 (first)" -> "Replace to Step 3" -> "Push to Step 4" -> go back to Step 1. Then repeat with "second". On the second visit to Step 3, it should show the "second" param and a different mount ID, confirming the old view was cleaned up from the DOM (issue #25640). With "Push to Step 1" instead, the first Step 3 stays in history, so it should stay hidden while the new one shows "second".</TestDescription>
0 commit comments