2016-10-18 30 views
4

我得到了以下结构:Angular2如何直接导入一个懒加载模块?

+--AppModule 
| +--OverviewModule 
| | +--OtherModule1 
| | +--OtherModule2 
| | +--OtherModule3 

要加载OverviewModule我使用延迟加载。这是我的AppModule航线配置:

const appRoutes: Routes = [ 
    { 
     path: 'overview', 
     loadChildren: 'app/injus/views/overview.module#OverviewModule' 
    }, 
    { 
     path: '', 
     redirectTo: 'overview', 
     pathMatch: 'full' 
    }, 
    { 
     path: '**', 
     component: PageNotFoundComponent 
    } 
]; 

当路径是'overview'它显示我的概述模块。当路径为''时,我希望它转到“概览”。不幸的是,这是行不通的。

概述路由:

export const overviewRoutes: Routes = [ 
    { 
     path: '', 
     component: OverviewComponent, 
     children: [ 
      { 
       path: '', 
       redirectTo: 'othermodule1', 
       pathMatch: 'full' 
      }, 
      { 
       path: 'othermodule1', 
       loadChildren: 'app/injus/views/othermodule1/othermodule1.module#otherModule1' 
      }, 
      { 
       path: 'othermodule2', 
       loadChildren: 'app/injus/views/othermodule2/othermodule2.module#2otherModule1' 
      }, 
      { 
       path: 'othermodule3', 
       loadChildren: 'app/injus/views/othermodule2/othermodule3.module#3otherModule1' 
      } 
     ] 
    } 
]; 

我如何可以直接到延迟加载的模块?

+0

在OverviewComponent中有'吗? –

+0

是的,我有一个路由器插座 –

回答

0

所以我找到了我的问题的原因。我正在导入我的AppModule中的OtherModule,导致OtherModule加载路径''

0

请您尝试一下它应该工作:

主要问题出口常量overviewRoutes:路线= []

export const overviewRoutes: Routes = [ 
    { 
     path: '', 
     component: OverviewComponent, 
    }, 
    { 
     path: '', 
     component: OverviewComponent, 
     children: [ 
      { 
       path: 'othermodule1', 
       loadChildren: 'app/injus/views/othermodule1/othermodule1.module#otherModule1' 
      }, 
      { 
       path: 'othermodule2', 
       loadChildren: 'app/injus/views/othermodule2/othermodule2.module#2otherModule1' 
      }, 
      { 
       path: 'othermodule3', 
       loadChildren: 'app/injus/views/othermodule2/othermodule3.module#3otherModule1' 
      } 
     ] 
    } 
]; 

添加

Routes = [ 
    { 
     path: '', 
     component: OverviewComponent, 
     } 
    .... 
    ] 

删除

children: [{ 
     path: '', 
     redirectTo: 'othermodule1', 
     pathMatch: 'full' 
    }, 
    .... 
    ] 
0

你的配置似乎是正确的......

我创建了一个Plnkr你:Plnkr

尝试查看路径模块和<router-outlet>位置在模板 (您可以在需要<router-outlet> AppComponent模板和OverviewComponent中的另一个)