即时设置根页面,然后在确认后

时间:2017-02-23 13:18:13

标签: angular typescript ionic2

我有一个Ionic 2应用程序,当用户想要返回时我需要显示确认提醒。

我已经有了它的工作:

ionViewCanLeave() {

    return new Promise((resolve, reject) => {
        let confirm = this.alertCtrl.create(
            {
                //title: 'Are you sure?',
                message: this.CONFIRM_EXIT_MSG,
                buttons: [{
                text: 'Si',
                handler: () => {
                    this.stopAfterLeave();
                    resolve();
                },
            },
            {
                text: 'No',
                handler: () => {
                    reject();
                }
            }],
        });

        confirm.present();

        this.customizeConfirmPrompt();
    });
}

ionViewWillLeave(): void {

    this.goToHomePage();
}

public goToHomePage(): void {

    this.navCtrl.setRoot(HomePage,
    {

    },
    {
        animate: true,
        direction: 'back'
    });
}

但问题是:当用户确认返回时,此页面会弹出(),1秒后会转到主页。

它类似于:主页 - >一页 - >其他页面 - >实际页面

我在"实际页面",当按下本机后退按钮或导航栏后退按钮时,我需要设置root" HomePage",而是转到"其他页面"然后转到" HomePage"

1 个答案:

答案 0 :(得分:0)

要转到Root页面,您可以使用此

public popToRoot(){
 this.navCtrl.popToRoot();
}


<ion-buttons>
  <button ion-button (click)="popToRoot()" icon-only>
    <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon>
  </button>
</ion-buttons>