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?
In my case it worked liked this
So, whether you go back with the soft/hard button or just pop() manually, the previous view will be skipped.
You can do this by modifying the navigation controller stack using insertPage method.
Here 0 refers to the position where you want to insert your page. In above code, 0 will be your home page and 1 will be your search page. Use this command in your DetailPage to navigation pop to SearchPage.
For more information check http://ionicframework.com/docs/v2/api/navigation/NavController/
I answered a similar question on here and it seems to apply for yours too. Since I'm lazy loading the modules, popTo() only seems to work when I pass an object from the NavController.getViews() array. With that said, you can try something like this:
Or something more verbose like this:
If you want to change the order, you may getViews().reverse().filter() or views.reverse().some(). This is with Ionic 3 and ES5's Array.some()
ok, found a solution. It looks like it works ... at least for the moment
Try this! Once you are in the
DetailPage
, do:I also came across to same problem and found the solution, it is similar to the accepted answer but without loop and bit more details so I hope this helps someone to understand it.
So here's the flow:
And here are the respective index:
If you want to go back to SearchPage from the DetailPage, you basically want to remove ResultPage from the stack when you push DetailPage.
So try this code on the ResultPage when you push DetailPage:
Hope this helps someone somewhere.