2016-12-26 126 views
1

當我嘗試下面的代碼在PlunkrPageNotFoundComponent被加載在我看來:角2路由器不匹配的路徑

的src/APP-routing.module(節選)

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

當我除去wildcard路徑I獲得所需的結果(組分one在視圖中被加載):

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

我錯過了什麼?

這裏有一個plunker https://embed.plnkr.co/MxM5JCJmwHVVSuTdfWZg/

回答

1

變化@NgModule這樣的:

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

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

由於OneModuleAppRoutingModule後,您在OneModule路徑在AppRoutingModule's通配符路徑丟失。

+0

這是我見過的最快最好的答案!謝謝!它現在有效! –

+1

@EugeneEpifanov哈哈,很高興我可以幫助! – echonax