zyra / ionic-super-tabs

Swipeable Tabs for Ionic
MIT License
664 stars 192 forks source link

When the first supertabs loaded in the app has only 1 tab, the others have an error : Cannot read property 'getActiveChildNavs' of undefined #309

Closed Stephane84 closed 5 years ago

Stephane84 commented 6 years ago

Hello, here is the bug :

In a new ionic3 app, use supertabs in a page (Page1). In Page1, supertabs must have only one tab (Tab1). In Tab1, put a button to navigate to another page (Page 2) using this : this.app.getRootNavs()[0].push("Page2Page"); Page 2 use supertabs with 2 tabs (Tab2 and Tab3)

When we ionic serve the app, we first arrived in Page1, so, the first supertabs of the app who is loaded has only one tab Clic to the button to go to Page2 where there is another supertabs We obtain the js error : Cannot read property 'getActiveChildNavs' of undefined

In my project, i have some pages using supertabs with *ngIf conditions on tabs, and sometimes, i have only one tab to display. If the fist supertabs displayed in the app has only 1 tab in supertabs, the others pages using supertabs have the js error.

To make sure, change the rootPage to arrived in Page2 instead of Page1 when ionic serve, and see that it works if you go to Page1 from Page2. Because, the first supertab loaded as more than 1 tab.

I have a temporary hack :

Display in the same page before the one tab supertabs (or in a previous page you visited before) a superTabs in style display:none, with at less 2 tabs, (linked to empty page)

ex :

<super-tabs style="display: none">
        <super-tab [root]="emptyPage"></super-tab>
        <super-tab [root]="emptyPage"></super-tab>
</super-tabs>

full js error :

core.js:1449 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'getActiveChildNavs' of undefined
TypeError: Cannot read property 'getActiveChildNavs' of undefined
    at findTopNavs (app.js:408)
    at app.js:414
    at Array.forEach (<anonymous>)
    at findTopNavs (app.js:413)
    at app.js:414
    at Array.forEach (<anonymous>)
    at findTopNavs (app.js:413)
    at app.js:232
    at Map.forEach (<anonymous>)
    at App.getActiveNavContainers (app.js:231)
    at findTopNavs (app.js:408)
    at app.js:414
    at Array.forEach (<anonymous>)
    at findTopNavs (app.js:413)
    at app.js:414
    at Array.forEach (<anonymous>)
    at findTopNavs (app.js:413)
    at app.js:232
    at Map.forEach (<anonymous>)
    at App.getActiveNavContainers (app.js:231)
    at c (polyfills.js:3)
    at new t (polyfills.js:3)
    at webpackJsonp.274.__awaiter (super-tabs.js:2)
    at SuperTabs.webpackJsonp.274.SuperTabs.ngAfterViewInit (super-tabs.js:221)
    at callProviderLifecycles (core.js:12748)
    at callElementProvidersLifecycles (core.js:12715)
    at callLifecycleHooksChildrenFirst (core.js:12698)
    at checkAndUpdateView (core.js:13853)
    at callViewAction (core.js:14195)
    at execComponentViewsAction (core.js:14127)

Versions info : @ionic/cli-utils : 1.19.2 ionic (Ionic CLI) : 3.20.0 @ionic/app-scripts : 3.1.9 Cordova Platforms : android 6.2.3 Ionic Framework : ionic-angular 3.9.2

ionic2-super-tabs : 4.2.2

traed commented 6 years ago

This is probably the same as my issue (#308), since my super tabs also had only one tab when I tested this.

ChrizC commented 6 years ago

Hi - I've submitted a fix for this in PR #323 - if you could show support for that PR we can get it fixed properly