0
votes

I have a dynamic tabs page in my Ionic2 app that looks like this:

<ion-tabs #myTabs class="tabs-md" type="md" [tabsHighlight]="true" [selectedIndex]="mySelectedIndex">
  <ion-tab *ngFor="let tab of tabRoots" [root]="tab.page" [tabTitle]="tab.name" [tabIcon]="tab.icon"></ion-tab>
</ion-tabs>

When the user taps on a tab that is already selected and is therefore the root page already, the page will still reload. The issue is that I have a few custom animations that rerun when this happens. So I want to disable the ability to navigate to your same root page.

I've tried putting

ionViewCanLeave() {
  return //viewchild of #myTabs and returns true if next page does not equal current page.
}

This worked in that it stopped the refresh of the current root page, but the app crashes when navigating to another page that isnt a root (a child page) because myTabs reference is undefined.

Any advice on how to accomplish this? I would prefer to handle this from my tabs controller.

2

2 Answers

0
votes

Try : ionSelected() { // DO SOMETHING OR NOT }

In your 'HomePage' for example.

Links : https://forum.ionicframework.com/t/capturing-ion-tab-click-on-active-tab-event/56594/27

I Hope I could help you.

0
votes

This was caused by a bug in ionic which was fixed in version 3.0.1

https://github.com/ionic-team/ionic/pull/11084