Skip to content

Commit ca03a6d

Browse files
committed
fix(nav): reset direction state when navigation is canceled
1 parent 6490797 commit ca03a6d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/angular/common/src/providers/nav-controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Location } from '@angular/common';
22
import { Injectable, Optional } from '@angular/core';
3-
import { NavigationExtras, Router, UrlSerializer, UrlTree, NavigationStart } from '@angular/router';
3+
import { NavigationExtras, Router, UrlSerializer, UrlTree, NavigationStart, NavigationCancel, NavigationError } from '@angular/router';
44
import type { AnimationBuilder, NavDirection, RouterDirection } from '@ionic/core/components';
55

66
import { IonRouterOutlet } from '../directives/navigation/router-outlet';
@@ -42,6 +42,14 @@ export class NavController {
4242
this.guessDirection = this.guessAnimation = id < this.lastNavId ? 'back' : 'forward';
4343
this.lastNavId = this.guessDirection === 'forward' ? ev.id : id;
4444
}
45+
46+
// Reset explicit direction when navigation is canceled (e.g., guard rejection)
47+
// to prevent stale direction from leaking into the next navigation
48+
if (ev instanceof NavigationCancel || ev instanceof NavigationError) {
49+
this.direction = DEFAULT_DIRECTION;
50+
this.animated = DEFAULT_ANIMATED;
51+
this.animationBuilder = undefined;
52+
}
4553
});
4654
}
4755

0 commit comments

Comments
 (0)