diff --git a/angular/src/navigation/ion-nav-controller.ts b/angular/src/navigation/ion-nav-controller.ts index 49ff5ec383..743c18a0b6 100644 --- a/angular/src/navigation/ion-nav-controller.ts +++ b/angular/src/navigation/ion-nav-controller.ts @@ -3,15 +3,26 @@ import { Injectable } from '@angular/core'; @Injectable() export class NavController { - private goback = false; + private direction = 0; + private stack: string[] = []; setGoback() { - this.goback = true; + this.direction = -1; } - consumeGoBack() { - const goback = this.goback; - this.goback = false; - return goback; + consumeDirection() { + if (this.direction === 0) { + const index = this.stack.indexOf(document.location.href); + if (index === -1) { + this.stack.push(document.location.href); + this.direction = 1; + } else { + this.stack = this.stack.slice(0, index + 1); + this.direction = -1; + } + } + const direction = this.direction; + this.direction = 0; + return direction; } } diff --git a/angular/src/navigation/ion-router-outlet.ts b/angular/src/navigation/ion-router-outlet.ts index 3ebe740af6..26d67906d8 100644 --- a/angular/src/navigation/ion-router-outlet.ts +++ b/angular/src/navigation/ion-router-outlet.ts @@ -19,7 +19,8 @@ export class IonRouterOutlet implements OnDestroy, OnInit { @Output('deactivate') deactivateEvents = new EventEmitter(); constructor( - private parentContexts: ChildrenOutletContexts, private location: ViewContainerRef, + private parentContexts: ChildrenOutletContexts, + private location: ViewContainerRef, private resolver: ComponentFactoryResolver, private elementRef: ElementRef, @Attribute('name') name: string, @@ -133,9 +134,12 @@ export class IonRouterOutlet implements OnDestroy, OnInit { const navEl = this.elementRef.nativeElement as HTMLIonRouterOutletElement; navEl.appendChild(enteringEl); + const direction = this.navCtrl.consumeDirection(); + await navEl.componentOnReady(); await navEl.commit(enteringEl, { - direction: this.navCtrl.consumeGoBack() ? NavDirection.back : NavDirection.forward + duration: direction === 0 ? 0 : undefined, + direction: direction === -1 ? NavDirection.back : NavDirection.forward }); if (this.deactivated) {