3

I am following this https://ionicframework.com/docs/components/#tabs

After login i am using this key to navigate to next page this.navCtrl.setRoot("tabs"); i am automatically seen home tabs / tab1 as selected in my tabs.

I have totally 5 tabs Tab1,Tab2,Tab3,Tab4,Tab5.

Initial Tab1 is getting selected. When i navigate to any tab like Tab2/Tab3 and click on device back button i am not able to navigate to my previous Tab.

My Understanding:

Since i have 5 Tabs so when every tab is selected new stack is been initiated.

I believe i have to navigate to Stack to Stack is it possible and if so any piece of advice will help me .

Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117
  • I think [previousTab(trimHistory) function](https://ionicframework.com/docs/api/components/tabs/Tabs/#previousTab) could help. Just handle back button click and select previous tab – Duannx Nov 03 '17 at 01:58
  • How to make use of it any example would help much @Duannx – Mohan Gopi Nov 03 '17 at 04:21

2 Answers2

0

Try this:

In tabs.html

<ion-tabs #myTabs>
    ...
</ion-tabs>

In tabs.ts

  @ViewChild('myTabs') tabRef: Tabs;
  constructor(public navCtrl: NavController, public platform: Platform) {
    platform.ready().then(() => {
      platform.registerBackButtonAction(() => {
        let tabPrv = this.tabRef.previousTab(false);//Remember pass false
        if (tabPrv) this.tabRef.select(tabPrv.index);//Here you go back to prv Tab
        return false;//Make sure return false to prevent exit app
      })
    })
  }
Duannx
  • 7,501
  • 1
  • 26
  • 59
0
let tabPrv = this.tabRef.previousTab(true); //Remember pass true
if (tabPrv) this.tabRef.select(tabPrv.index);

If you pass true it will remember all previous history and if you pass false it will remember just previous tab .

David Buck
  • 3,752
  • 35
  • 31
  • 35