3

I'm using Ionic 2 and have a set of tabs. Each tab maintains its own navigation stack.

The user is able to go several pages deep into any of the tabs and then switch tab.

The problem is that there are interactions in tab 1 that effect the content of tab 2. What I am finding is that if the user does certain actions in a certain order, then I get an error:

Runtime Error

Uncaught (in promise): removeView was not found

I believe this is because Ionic is attempting to remove a view that no longer exists because the content has changed.

In Tab 1, the user presses a button to load Tab 2. The app saves the selection they made in local storage, which Tab 2 then loads up when on the root page. I select Tab 2 using the following code:

this.navCtrl.parent.select(1);

I believe I can prevent this problem by going to the root of the nav stack when the tab is selected, but how can I do that?

I tried:

this.navCtrl.parent.select(1);
this.navCtrl.parent.goToRoot();

But with this, nothing happens. The tab doesn't change and there are no errors.

So, my question: How can I change a tab and navigate to the root of the navigation stack from another tab?

Community
  • 1
  • 1
Mike
  • 8,767
  • 8
  • 49
  • 103
  • You can set the root for tab 1 (this.navCtrl.setRoot(tab1)). if this does not work for you then please put your code in plunker where this issue can be reproduced. – AddWeb Solution Pvt Ltd Oct 16 '17 at 13:13

1 Answers1

1

For some pages outside the regular navigation stack of my application (Ionic 3 with lazy loading), I use the following code, setting the root (setRoot) before navigate to the new page (popToRoot):

this.navCtrl
    .setRoot('YourPage')
    .then(() => {
      this.navCtrl.popToRoot();
    }, err => console.log(err))
TGrif
  • 5,725
  • 9
  • 31
  • 52
  • How would I do this with my tabs though? Your code does open my page, but it does it in the current navstack, rather than on the other tab. Is there a way I can reference my tabs and navigate back to root? – Mike Oct 16 '17 at 14:05
  • Not tested, but I think you can do it with _this.app.getRootNav()_ instead of _navCtrl_, as describe [here](https://stackoverflow.com/a/42601740/5156280). – TGrif Oct 16 '17 at 14:44