2017-06-01 62 views
0

配置子路由後出現以下錯誤。如何正確配置子路由?錯誤:未捕獲(承諾):錯誤:無法匹配任何路由。 URL段:'parent/child1

錯誤:未捕獲(承諾):錯誤:無法匹配任何路由。 URL段:「父/ child1

app.routing.ts

{ path: 'home', component: homeComponent}, 
    { path: 'about', component: aboutComponent}, 
    { path: 'parent', component: parentComponent, 
    children:[ 
    { 
     path: '', 
     redirectTo: '/parent/child1', 
     pathMatch: 'full' 
    }, 
    { 
     path: 'child1', 
     component: child1Component, 
     outlet: 'subRouter' 
    }, 
    { 
     path: 'child2', 
     component: child2Component, 
     outlet: 'subRouter' 
    }] 
    }, 
{ path: '**', redirectTo: 'home', pathMatch: 'full' } 

在我的index.html,我有<router-outlet></router-outlet>

在我parent.htm(爲父級)我有<router-outlet name="subRouter"></router-outlet>

我錯過了什麼?爲什麼我得到那個錯誤?我該如何解決這個錯誤?

回答

0

parent路由子路徑''路徑重定向應改爲以下,並明確提及outlet:component的值。

redirectTo: '/child1(subRouter:child1)' 

因爲/parent將隱式包含在您從子路由重定向時。

+0

做出這個改變後,我得到了與URL段相同的錯誤:'child1' – Keshav1007

+0

沒有。仍然得到相同的錯誤。指定出口和組件值後 – Keshav1007

相關問題