【发布时间】:2017-02-28 16:03:59
【问题描述】:
我有一个 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'
});
}
但问题是:当用户确认返回时,该页面pop() 1秒后返回首页。
就像:主页 --> 一个页面 --> 其他页面 --> 实际页面
我在“实际页面”,当按原生返回按钮或导航栏返回按钮时,我需要将“主页”设置为root,而不是转到“其他页面”然后转到“主页”
【问题讨论】:
-
如何在
goToHomePagesetRoot之前添加这一行this.navCtrl.pop(TheActualPage)
标签: angular typescript ionic2