zoukankan      html  css  js  c++  java
  • [Angular Router] Lazy loading Module with Auxiliary router

    Found the way to handle Auxiliary router for lazy loading moudle and erge load module are different. 

    In Erge loading, it is recommended to create a shell component, inside shell component you need to define the router-outlet for each Auxiliary routes and primary route.

    const routes: Routes = [
      ...
      { path: 'speakers', component: SpeakersComponent, children: [
        { path: 'speakersList', component: SpeakersListComponent, outlet: 'list' },
        { path: ':id', component: BioComponent, outlet: 'bio' }
      ] },
    ];

    For example, in the code above, 'SpeakersComponent' is shell component.

    <div class="columns">
      <md-card>
        <router-outlet name="list"></router-outlet>
      </md-card>
      <md-card>
        <router-outlet name="bio"></router-outlet>
      </md-card>
    </div>

    Inside the html, it defines all the auxilliary routes for shell component. 


    But the story changes when you use lazy loading...

    For example, we lazy load a feature module inside our root routes configuration:

      {
        path: 'preview',
        loadChildren: 'app/preview/preview.module'
      },

    And here is the feature module routes:

    const routes = [
      {
        path: '',
        component: PreviewLeftComponent
      },
      {
        path: ':id',
        component: PokemonDetailComponent
      },
      {
        path: ':id',
        outlet:'aux',
        component: PreviewDetailComponent
      }
    ];

    There is one auxiliary route. But here we didn't use any shell component.

    This is because I found, when using lazy loading, Angular doesn't goes into Shell component html to find auxiliary routes' router-outlet, it goes to root component,

    So we have to define the auxiliary route outlet inside root component:

    <!-- aoo.component.html -->
    
    <md-sidenav-layout>
      <md-sidenav align="start" mode="side" opened>
        <app-sidenav></app-sidenav>
      </md-sidenav>
      <div class="main-content">
        <router-outlet></router-outlet>
      </div>
      <md-sidenav align="end" mode="side" [opened]="curtPath === 'preview'">
        <router-outlet name="aux"></router-outlet>
      </md-sidenav>
    </md-sidenav-layout>

    Github, Talk

  • 相关阅读:
    Android程序反编译的方法(转)
    VMware的Easy Install安装
    Oracle ORA12514:TNS:监听程序当前无法识别连接描述符中请求的服务
    Java Eclipse 如何导入外部Jar包
    Oracle IMP00010: 不是有效的导出文件,标题验证失败
    怎样取消Windows 2003 server 意外关机提示
    没有文件扩展“.vbs”的脚本引擎的解决方案
    Oracle init.ora常用配置详解
    eclipse断点调试 出现Source not found
    VMware Workstation 8
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6193157.html
Copyright © 2011-2022 走看看