I have the following navigation-case:
Home -> navCtrl.push(SearchPage) -> navCtrl.push(ResultPage)
or
Home -> navCtrl.push(SearchPage) -> navCtrl.push(ResultPage) -> navCtrl.push(DetailPage)
I want to navigate back to SearchPage. In first case, there is no problem, I can use
this.navCtrl.pop()
But, in second case, I try to use
this.navCtrl.popTo(SearchPage)
and this does not work as expected. Ionic navigates only one page back in stack. I know there is an issue with popTo() (https://github.com/driftyco/ionic/issues/6513)
How can I solve this problem?
Try this! Once you are in the DetailPage, do:
this.navCtrl.remove(2,1); // This will remove the 'ResultPage' from stack.
this.navCtrl.pop(); // This will pop the 'DetailPage', and take you to 'SearchPage'
this.navController.push(SearchPage).then(() => {
const index = this.viewCtrl.index;
this.navController.remove(index, 1); //this will remove page3 and page2
});
Include this code in your component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With