Skip to content

Commit

Permalink
fix(angular): back-button does not push view
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 4, 2018
1 parent 4db687e commit bb46b5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions angular/src/directives/navigation/ion-back-button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { IonRouterOutlet } from './ion-router-outlet';
import { Router } from '@angular/router';
import { NavController } from '../..';

@Directive({
selector: 'ion-back-button'
Expand All @@ -18,6 +19,7 @@ export class IonBackButton {
constructor(
@Optional() private router: Router,
@Optional() private routerOutlet: IonRouterOutlet,
private navCtrl: NavController,
private elementRef: ElementRef,
) {}

Expand All @@ -27,6 +29,7 @@ export class IonBackButton {
this.routerOutlet.pop();
ev.preventDefault();
} else if (this.router && this.defaultHref != null) {
this.navCtrl.setGoback();
this.router.navigateByUrl(this.defaultHref);
ev.preventDefault();
}
Expand Down
11 changes: 8 additions & 3 deletions angular/src/directives/navigation/router-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class StackController {

async setActive(enteringView: RouteView, direction: number | undefined) {
const leavingView = this.getActive();
const reused = this.insertView(enteringView);
const forcedGoBack = direction === -1;
const reused = this.insertView(enteringView, forcedGoBack);
direction = direction != null ? direction : (reused ? -1 : 1);
await this.transition(enteringView, leavingView, direction, this.canGoBack(1));

Expand All @@ -50,14 +51,18 @@ export class StackController {
this.router.navigateByUrl(view.url);
}

private insertView(enteringView: RouteView): boolean {
private insertView(enteringView: RouteView, forcedGoBack: boolean): boolean {
if (this.stack) {
const index = this.views.indexOf(enteringView);
if (index >= 0) {
this.views = this.views.slice(0, index + 1);
return true;
} else {
this.views.push(enteringView);
if (forcedGoBack) {
this.views = [enteringView];
} else {
this.views.push(enteringView);
}
return false;
}
} else {
Expand Down

0 comments on commit bb46b5f

Please sign in to comment.