2016-10-18 9 views
4

私は、次の構造を得た:私は遅延ロードを使用OverviewModuleロードするにAngular2遅延ロードされたモジュールに向ける方法は?

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

を。これは私の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

それが動作するはずです、それを試してみてください:輸出のconst 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, 
     } 
    .... 
    ] 

を追加します。

0

あなたの設定が正しいように思わ...

私はあなたのためPlnkrを作成しました:Plnkr

あなたがで<router-outlet>を必要とする( 、テンプレート内のモジュールと<router-outlet>位置にパスをチェックしてみてくださいAppComponentテンプレートとOverviewComponentの別のテンプレート)

関連する問題