Repository navigation
fix(angular): keep the navigateRoot direction when a guard redirects - #31843
Open
mokshupadhyay wants to merge 1 commit into
Open
mokshupadhyay wants to merge 1 commit into
mokshupadhyay wants to merge 1 commit into
Conversation
A guard that returns a UrlTree cancels the navigation with a Redirect code before starting the redirect. Resetting the direction on that cancel pushed the redirected page onto the stack instead of setting it as root. Keep the direction, animation and animation builder when the navigation is redirected or superseded, and reset them for every other cancel or error. resolves ionic-team#31071
|
@mokshupadhyay is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue number: resolves #31071
What is the current behavior?
Since #30955,
NavControllerresets the requested direction toautoon everyNavigationCancel. When a guard returns aUrlTree, Angular cancels the original navigation withNavigationCancellationCode.Redirectbefore starting the redirect, sonavigateRoot('/guarded')loses itsrootdirection and the redirected page is pushed onto the existing stack. The old pages stay, and the back button is shown. The same happens when a pending navigation is superseded by anavigateRootcall.What is the new behavior?
NavigationCancelwith the codeRedirectorSupersededByNewNavigationkeeps the direction, animation and animation builder, because the navigation continues (the same way Angular's router treats those two codes). This is the change suggested on the issue.NavigationErrorstill reset them, so the case from fix(nav-controller): reset direction state when navigation is canceled #30955 (a guard rejecting a back navigation) is unchanged. The history-entry handling in that block is unchanged too.back-history.spec.ts: from page C,navigateRootto the existing/standalone/back-history/redirectedroute, whose guard redirects to D; D is shown and A, B and C are no longer in the DOM.Does this introduce a breaking change?
Other information
Tested with the
ng21test app (headless Chromium): the new test fails onmain(app-back-history-astill present) and passes with the change. With the change, the standalone back-history, nav, router-outlet, back-button, router-link and tabs specs and the lazy routing, navigation, router-link, nested-outlet, standalone-routing and tabs specs pass (83 tests).npm run lintandnpm run testinpackages/angularpass. I didn't run the other Angular versions' test apps locally.An AI coding assistant (Claude Code) helped me write this; I reviewed the change and the test results.