Close push nav when change tab


#1

Hi,

I have 2 tabs.

First, from tab 1, I open a page with NavController and push.
Then I go to tab 2 and, on returning to tab 1, the page on which I clicked is still open. I want when I change Tab to close those pages, can anyone help me?

Thank you


#2

You can try navCtrl.pop() to remove the page from navigation stack.


#3

I think this breaks the UX contract of tabs. Tabs are meant to be little "sub-app"s that are independent of one another, so actions taken inside one of them should not alter the navigation state of another.


#5

I’m sorry but I’ve never used this. Could you give me an example?


#6

I understand but, can’t u close the sub-page when change tab?


#7

Using this.app.getRootNav().push is a good idea. Or you can do this in your tabs template using tabsHideOnSubPages attribute.

<ion-tabs>
  <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="information-circle" tabsHideOnSubPages="true"></ion-tab>
  <ion-tab [root]="tab3Root" tabTitle="Contact" tabIcon="contacts"></ion-tab>
</ion-tabs>

#8

I’m not talking can/can’t. I’m talking should/shouldn’t.


#9

Hi @NurGuz this.app.getRootNav().push used in where ?