Ionic 2:popToRoot()不会重定向到根组件(主页) [英] Ionic 2 : popToRoot() doesn't redirect to root component ( home page )
问题描述
此功能中的每件事都可以正常工作,但 this.nav.popToRoot()在该位置无法正常工作。
如果我将它移动到函数的开头,它可以正常工作。
没有人对此有合理的解释。
Every thing work fine in this function, but this.nav.popToRoot() doesn't work in that location. If I move it to the beginning of the function it works correctly. Doesn't any one has a logical explanation for this.
提前感谢您的时间和考虑。
Thank you in advance for your time and consideration.
以下是booking.ts组件中的代码:
Here is the code in a booking.ts component:
book(){
let newReservation = {
_id: this.room._id,
from: this.details.from.substring(0,10),
to: this.details.to.substring(0,10)
}
let loading = this.loadingCtrl.create({
content: "Booking room..."
});
loading.present();
this.roomsService.reserveRoom(newReservation).then((res) => {
loading.dismiss();
console.log("Room reserved successfully ... ");
this.nav.popToRoot();
}, (err) => {
console.log(err);
});
}
推荐答案
对我来说也是如此,但我设法替换整个历史堆栈,在我的情况下,我不需要保留历史堆栈,这就是我做的方式:
It happens the same to me, but i managed to replace the whole history stack, in my case after a certain point i don't need to keep the history stack, this is how i did it:
this.navCtrl.setPages([
{ page: RootPageHere }
]);
在promise中运行。
Works inside of a promise then function.
这篇关于Ionic 2:popToRoot()不会重定向到根组件(主页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!