Skip to content

fix(nav-controller): reset direction state when navigation is canceled#30955

Open
ShaneK wants to merge 2 commits intomainfrom
IONIC-85
Open

fix(nav-controller): reset direction state when navigation is canceled#30955
ShaneK wants to merge 2 commits intomainfrom
IONIC-85

Conversation

@ShaneK
Copy link
Member

@ShaneK ShaneK commented Feb 13, 2026

Issue number: resolves internal


What is the current behavior?

When a CanDeactivate guard cancels a back navigation (like when it's initiated by ion-back-button), the NavController’s explicit direction state (back) is never consumed because consumeTransition() is not called for canceled navigations. This stale direction leaks into the next forward navigation, causing it to be incorrectly treated as a back/root navigation.

What is the new behavior?

The NavController now listens for NavigationCancel and NavigationError router events and resets direction, animated, and animationBuilder back to their defaults. This ensures stale state from a canceled navigation does not affect subsequent navigations. The reset puts the NavController into 'auto' mode, which correctly uses guessDirection for the next navigation.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Current dev build:

8.7.18-dev.11771020096.1ca03a6d

@vercel
Copy link

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Feb 13, 2026 10:15pm

Request Review

@ShaneK ShaneK marked this pull request as ready for review February 13, 2026 22:09
@ShaneK ShaneK requested a review from a team as a code owner February 13, 2026 22:09
@ShaneK ShaneK requested a review from thetaPC February 13, 2026 22:09
@github-actions github-actions bot added the package: angular @ionic/angular package label Feb 13, 2026
Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ShaneK ShaneK added this pull request to the merge queue Feb 17, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 17, 2026
#30955)

Issue number: resolves internal

---------

<!-- 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?
When a CanDeactivate guard cancels a back navigation (like when it's
initiated by ion-back-button), the NavController’s explicit direction
state (back) is never consumed because consumeTransition() is not called
for canceled navigations. This stale direction leaks into the next
forward navigation, causing it to be incorrectly treated as a back/root
navigation.

## What is the new behavior?
The NavController now listens for NavigationCancel and NavigationError
router events and resets direction, animated, and animationBuilder back
to their defaults. This ensures stale state from a canceled navigation
does not affect subsequent navigations. The reset puts the NavController
into 'auto' mode, which correctly uses guessDirection for the next
navigation.

## 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

Current dev build:
```
8.7.18-dev.11771020096.1ca03a6d
```
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants