2016-12-26 3 views
1

Wenn ich versuche, den folgenden Code in PlunkrPageNotFoundComponent ist aus meiner Sicht geladen:Angular 2 Router entspricht nicht den Pfad

src/app-routing.module (Auszug)

const appRoutes: Routes = [ 
    { path: '', redirectTo: '/one', pathMatch: 'full' }, 
    { path: '**', component: PageNotFoundComponent } 
]; 

Wenn ich entfernen wildcard Pfad I das gewünschte Ergebnis zu erhalten (Komponente one wird in der Ansicht geladen):

const appRoutes: Routes = [ 
    { path: '', redirectTo: '/one', pathMatch: 'full' }, 
]; 

Was fehlt mir?

Hier ist ein Plunker https://embed.plnkr.co/MxM5JCJmwHVVSuTdfWZg/

Antwort

1

ändern @NgModule wie folgt aus:

@NgModule({ 
    imports: [ 
    BrowserModule, 
    OneModule,//<- before root routing module 
    AppRoutingModule, 

    ], 
    declarations: [ AppComponent, PageNotFoundComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule {} 

Seit OneModule nach AppRoutingModule war, deine Pfade in OneModule in AppRoutingModule's Wildcard Pfad verloren.

+0

das war die schnellste und beste Antwort, die ich je hatte! Vielen Dank! Es funktioniert jetzt! –

+1

@EugeneEpifanov haha, froh, ich könnte helfen! – echonax