Skip to content

Ionic v4 - Tabs are not Lazy Loading Children #14566

Closed

Description

@dmastag

Support Question

I noticed that on the Tab Starter that the children of the tabs module and tabs router are not lazy loaded.

https://github.com/ionic-team/starters/blob/master/angular/official/tabs/src/app/pages/tabs/tabs.module.ts

https://github.com/ionic-team/starters/blob/master/angular/official/tabs/src/app/pages/tabs/tabs.router.module.ts

Would this not be a performance Drag when I create a huge Tab based App? Since all my modules will have to be loaded in that Tab Module?

Activity

  1. ostno commented on Jun 4, 2018

    @ostno

    You can configure lazy loading for tabs, create a tabs.routing.module file and import it to tabs.module

    import { NgModule } from '@angular/core';
    import { RouterModule, Routes } from '@angular/router';
    
    import { TabsPage } from './tabs.page';
    
    const routes: Routes = [
        {
            path: 'tabs',
            component: TabsPage,
            children: [
                {
                    path: 'home',
                    outlet: 'home',
                    loadChildren: '../home/home.module#HomePageModule'
                },
                {
                    path: 'about',
                    outlet: 'about',
                    loadChildren: '../about/about.module#AboutPageModule'
                }
            ]
        },
        {
            path: '',
            redirectTo: '/tabs/(home:home)',
            pathMatch: 'full'
        }
    ];
    
    @NgModule({
        imports: [RouterModule.forChild(routes)],
        exports: [RouterModule]
    })
    export class TabsPageRoutingModule {}
    
    
  2. mhartington commented on Jun 4, 2018

    @mhartington
    Contributor

    This is something we're currently waiting for Angular to fix here

    angular/angular#10981

    After this is merged in, tabs we be able to be fully lazy loaded.

  3. GuilhermeBCC commented on Jun 11, 2018

    @GuilhermeBCC

    It would not be better to use an ion-segment with router-outlet?

    <ion-content>
       <router-outlet></router-outlet>
    </ion-content>
    
    <ion-footer>
       <ion-segment>
          <ion-segment-button routerLink="home">Home</ion-segment-button>
          <ion-segment-button routerLink="about">About</ion-segment-button>
       </ion-segment>
    </ion-footer>
    
    
  4. dmastag commented on Jun 12, 2018

    @dmastag
    Author

    @GuilhermeBCC I believe not
    As you won't be able to lazy load a whole application that way and therefor bigger applications that are build around tabs will then load quite longer

  5. pavillet commented on Jun 14, 2018

    @pavillet

    The angular issue has been fixed, or is supposed to be ;)

  6. dmastag commented on Jun 16, 2018

    @dmastag
    Author

    Yeahh, so just wait until its released in Angular and try to update my ionic v4 app

  7. TomDemulierChevret commented on Jun 19, 2018

    @TomDemulierChevret
    Contributor

    Angular 6.1.0-beta.1 contains their fix but isn't enough to fix the issue.
    I tried it and there is a style issue that prevent the page from rendering correctly :

    • Without lazy-loading
      wihout-lazy-loading
    • With lazy-loading
      with-lazy-loading

    The empty ng-component inserted by Angular receive the ion-page class instead of the real page.

  8. mhartington commented on Jun 19, 2018

    @mhartington
    Contributor

    The fix from angular is an internal fix at the moment. I'll be working with them to see what can be done to fix this.

  9. jing-zhou commented on Aug 8, 2018

    @jing-zhou

    this problem still persists on ionic v4.0.0-beta.1 and angular 6.1.1

    wjz@bj:~/ion/sarva$ ionic info
    
    Ionic:
    
       ionic (Ionic CLI)          : 4.0.5 (/home/wjz/.nvm/versions/node/v10.7.0/lib/node_modules/ionic)
       Ionic Framework            : @ionic/angular 4.0.0-beta.1
       @angular-devkit/core       : 0.7.2
       @angular-devkit/schematics : 0.7.2
       @angular/cli               : 6.1.2
       @ionic/ng-toolkit          : 1.0.0
       @ionic/schematics-angular  : 1.0.1
    
    Cordova:
    
       cordova (Cordova CLI) : 8.0.0
       Cordova Platforms     : android 7.0.0
    
    System:
    
       Android SDK Tools : 26.1.1
       NodeJS            : v10.7.0 (/home/wjz/.nvm/versions/node/v10.7.0/bin/node)
       npm               : 6.2.0
       OS                : Linux 4.4
    
    Environment:
    
       ANDROID_HOME : /home/wjz/Android/Sdk
       HTTP_PROXY   : http://127.0.0.1:42266/
       http_proxy   : http://127.0.0.1:42266/
       HTTPS_PROXY  : http://127.0.0.1:42266/
       https_proxy  : http://127.0.0.1:42266/
    
    

    package.json excerpt:

    "dependencies": {
        "@angular/common": "6.1.1",
        "@angular/core": "6.1.1",
        "@angular/forms": "6.1.1",
        "@angular/http": "6.1.1",
        "@angular/platform-browser": "6.1.1",
        "@angular/platform-browser-dynamic": "6.1.1",
        "@angular/router": "6.1.1",
        "@ionic-native/core": "5.0.0-beta.14",
        "@ionic-native/device": "5.0.0-beta.14",
        "@ionic-native/globalization": "5.0.0-beta.14",
        "@ionic-native/photo-library": "5.0.0-beta.14",
        "@ionic-native/splash-screen": "5.0.0-beta.14",
        "@ionic-native/status-bar": "5.0.0-beta.14",
        "@ionic/angular": "4.0.0-beta.1",
        "@ionic/ng-toolkit": "1.0.0",
        "@ionic/schematics-angular": "1.0.1",
        "@ionic/storage": "^2.1.3",
        "@ngx-translate/core": "10.0.2",
        "@ngx-translate/http-loader": "3.0.1",
        "base64-js": "^1.3.0",
        "cldr-tools": "^0.1.0",
        "client-oauth2": "^4.2.1",
        "cordova-android": "7.0.0",
        "cordova-plugin-device": "^2.0.2",
        "cordova-plugin-file": "^5.0.0",
        "cordova-plugin-globalization": "^1.11.0",
        "cordova-plugin-ionic-keyboard": "^2.1.2",
        "cordova-plugin-ionic-webview": "^2.0.2",
        "cordova-plugin-photo-library": "^2.1.1",
        "cordova-plugin-splashscreen": "^5.0.2",
        "cordova-plugin-statusbar": "^2.4.2",
        "cordova-plugin-whitelist": "^1.3.3",
        "cordova-sqlite-storage": "^2.3.3",
        "core-js": "^2.5.3",
        "fbsj": "^1.0.53",
        "flatbuffers": "^1.9.0",
        "http-string-parser": "0.0.6",
        "moment": "^2.22.2",
        "rxjs": "6.2.2",
        "serialize-javascript": "^1.5.0",
        "text-encoding": "^0.6.4",
        "uuid": "^3.3.2",
        "zone.js": "^0.8.26"
      },
      "devDependencies": {
        "@angular/cli": "6.1.2",
        "@angular/compiler": "6.1.1",
        "@angular/compiler-cli": "6.1.1",
        "@angular/language-service": "6.1.1",
        "@angular-devkit/architect": "0.7.2",
        "@angular-devkit/build-angular": "0.7.2",
        "@angular-devkit/core": "0.7.2",
        "@angular-devkit/schematics": "0.7.2",
        "@types/jasmine": "~2.8.6",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "~10.5.2",
        "codelyzer": "~4.4.2",
        "jasmine-core": "~2.99.1",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~2.0.2",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "~2.0.0",
        "karma-jasmine": "~1.1.1",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.4.0",
        "ts-node": "~7.0.0",
        "tslint": "~5.11.0",
        "typescript": "~2.7.2"
      },
      "description": "An Ionic project",
      "cordova": {
        "plugins": {
          "cordova-plugin-device": {},
          "cordova-plugin-globalization": {},
          "cordova-plugin-ionic-keyboard": {},
          "cordova-plugin-ionic-webview": {},
          "cordova-plugin-splashscreen": {},
          "cordova-sqlite-storage": {},
          "cordova-plugin-whitelist": {},
          "cordova-plugin-statusbar": {},
          "cordova-plugin-photo-library": {
            "PHOTO_LIBRARY_USAGE_DESCRIPTION": "To choose photos"
          }
        },
        "platforms": [
          "android"
        ]
      }
    }
    
  10. cvaliere commented on Aug 13, 2018

    @cvaliere

    @mhartington sorry to ping you like this, but any news on this? clearly an important feature that has been lost in migration

  11. bleuscyther commented on Aug 15, 2018

    @bleuscyther

    Yeah still an issue

  12. northcode7 commented on Aug 15, 2018

    @northcode7

    It doesnt work with Angular 6.1.2.

  13. mhartington commented on Aug 23, 2018

    @mhartington
    Contributor

    Hey folks. Yes, we're aware this is still an issue. We're looking into what we can do as currently the fix for this in Angular was not publicly exposed to other components. Will updated when we have more info

  14. daem0ndev commented on Aug 26, 2018

    @daem0ndev
    Contributor

    @mhartington in the mean time do you know of a way we can use the ion-tabbar directly. We want to implement the tab bar of buttons but without using the multiple outlets/page tabs. We simply want to have the look and feel of tabs but just use a single ion-router-outlet for the content area, this would allow us to continue our migration efforts of our large ionic app without having to wait for lazy loading to work with ion-tabs. I tried using with useRouter="false" but it still creates the ion-tab page element that covers the whole screen. ion-tabbar is also not exposed but it would be nice to just get a tab bar that is a "dumb" ui component that allows the developers to just get the look and feel and implement our own (click)/(ionSelect) handlers and what not.

  15. northcode7 commented on Aug 26, 2018

    @northcode7

    @daem0ndev , why dont you use the side menu for the time being.. and when it's fixed, just switch to the tabs..

  16. daem0ndev commented on Aug 27, 2018

    @daem0ndev
    Contributor

    @GRRook because we also have a side menu! also for early beta testing and UX usability tests, having the tab bar is helpful as the final product would have it. I was able to work past it by just making my own tab bar look alike that is essentially more of a shortcut bar to certain important routes/destinations of the app. it does not maintain a stack per tab or anything, just navigates forward based on the tab that is tapped.

  17. sudiptosen commented on Aug 27, 2018

    @sudiptosen

    In the ionic tabs template if I change the app-routing.module to the following, i see that it fails every other refresh. Error is: Cannot match any routes. URL segment: 'tabs'

    const routes: Routes = [ { path: '', redirectTo: '/tabs', pathMatch: 'full' }, { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' } ];

    I want to name the tabs route, so I can use it somewhere like: router.nagivate(['tabs'])

    navigate just errors out saying: Cannot match any routes. URL segment: 'tabs'

    Please help/confirm if this is related to Lazy Loading issue here.

    Appreciate it.

  18. locked as off topic and limited conversation to collaborators on Aug 27, 2018
  19. mhartington commented on Aug 27, 2018

    @mhartington
    Contributor

    Going to keep this issue locked for a bit, as most of the posts here are better suited for the Ionic forum. Please direct questions there.

    This issue will stay open in order to track lazy loading tabs for now.

  20. added
    package: core
    type: bug
    on Dec 3, 2018
  21. paulstelzer commented on Dec 7, 2018

    @paulstelzer
    Contributor

    I close this issue here because @manucorporat opened a new issue to track the process here -> #16619 - Please follow there for new information about lazy loading tabs

  22. removed
    package: core
    type: bug
    on Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions