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
bug: NavController direction gets lost when an Angular route guard returns a UrlTree #31071
cordova-res : not installed globally
native-run : not installed globally
System:
NodeJS : v22.22.0
npm : 10.9.4
OS : macOS
Additional Information
The issue was introduced in Ionic 8.7.18 with #30955. Because of that PR, a NavigationCancel leads to the NavController direction being lost. This is not necessarily bad, but it interacts poorly with Angular Route Guard redirects. When such a Route Guard returns a UrlTree, the initial navigation gets cancelled and a new navigation to that UrlTree gets started. Unfortunately, that new navigation loses the information about the NavController direction because of the intermittent NavigationCancel.
Preferred solution:
Detect whether the NavigationCancel was caused by a Route Guard redirecting somewhere else and in those cases retain the NavController direction.
Alternative solution:
If our preferred solution is not feasible, please provide guidance on how to achieve the intended outcome. In our case: Start a navigation such that if the Route Guards lead to a successful navigation, the rest of the navigation stack is removed.
Verified on 9.0.8. Since 8.7.18, NavController resets the requested direction to auto on every NavigationCancel. When a guard returns a UrlTree, Angular cancels the original navigation with NavigationCancellationCode.Redirect before starting the redirect, so the root set by navigateRoot is gone by the time the redirected page activates, and it gets pushed onto the existing stack. The same thing happens when a pending navigation is superseded by a navigateRoot call. Your suggested change matches what we found: skipping the reset for Redirect and SupersededByNewNavigation fixes both cases, the same way Angular's router treats those two codes as a continuing navigation.
Activity
StephanBradler commentedon Apr 13, 2026
Our suggestion: In
ionic-framework/packages/angular/common/src/providers/nav-controller.ts
Line 56 in 308aef5
ev instanceof NavigationCancelwith(ev instanceof NavigationCancel && ev.code !== NavigationCancellationCode.Redirect && ev.code !== NavigationCancellationCode.SupersededByNewNavigation).Please let us know if you agree. I hope the fix is as simple as it appears.
thetaPC commentedon Oct 20, 2026
Thanks for the report, and sorry for the delay.
Verified on 9.0.8. Since 8.7.18,
NavControllerresets the requested direction toautoon everyNavigationCancel. When a guard returns aUrlTree, Angular cancels the original navigation withNavigationCancellationCode.Redirectbefore starting the redirect, so therootset bynavigateRootis gone by the time the redirected page activates, and it gets pushed onto the existing stack. The same thing happens when a pending navigation is superseded by anavigateRootcall. Your suggested change matches what we found: skipping the reset forRedirectandSupersededByNewNavigationfixes both cases, the same way Angular's router treats those two codes as a continuing navigation.Tracked as a bug in
@ionic/angular.