2016-10-18 4 views
4

Ich habe die folgende Struktur:Angular2 wie zu einem faul geladenen Modul zu verweisen?

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

ich faul-Laden verwenden zu laden OverviewModule. Das ist mein AppModule Route config:

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

Wenn der Pfad 'overview' es zeigt meine Übersicht Modul. Wenn der Pfad '' ist, möchte ich, dass er auf 'Übersicht' geht. Leider wird das nicht funktionieren.

Übersicht Routing:

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' 
      } 
     ] 
    } 
]; 

Wie kann ich zu einem faulen geladenen Modul direkt?

+0

Haben Sie eine '' in der OverviewComponent? –

+0

Ja, ich habe eine Router-Steckdose –

Antwort

0

So fand ich die Ursache meines Problems. Ich importierte die OtherModules in meinem AppModule, was dazu führte, dass das OtherModule für den Pfad '' geladen wurde.

0

Bitte versuchen Sie es sollte es funktionieren:

Hauptproblem inExport konst overviewRoutes: die Routen = []

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' 
      } 
     ] 
    } 
]; 

hinzufügen

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

entfernen

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

Ihre Konfiguration korrekt zu sein scheint ...

habe ich eine Plnkr für Sie: Plnkr

Try Pfade Module zu überprüfen und die <router-outlet> Position in Ihren Vorlagen (Sie benötigen einen <router-outlet> in der AppComponent Vorlage und andere in OverviewComponent)

Verwandte Themen