Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 Angular NavController, pop back to second last page

Tags:

angular

ionic2

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?

like image 673
hydrococcus Avatar asked May 13 '26 08:05

hydrococcus


2 Answers

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'
like image 52
Malick Avatar answered May 15 '26 20:05

Malick


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.

like image 34
Arunkumar Papena Avatar answered May 15 '26 20:05

Arunkumar Papena