2017-10-06 127 views
0

我試圖在空路徑上使用輔助路線。例如:在兒童上的空路徑角輔助路線

{ 
    path: 'users', 
    children: [ 
     { 
     path: '', 
     component: UsersComponent, 
     }, 
     { 
     path: 'user-details', 
     outlet: 'list', 
     component: UserDetailsComponent 
     }, 
    ] 
    }, 

而且我UsersComponent模板:

<router-outlet></router-outlet> 
<router-outlet name="list"></router-outlet> 

但是,當我試圖導航到以下網址: 1. http://localhost:4200/users(list:user-details) 2. http://localhost:4200/(users//list:user-details)

我出現此錯誤:

Cannot match any routes. URL Segment: 'users'

+0

輔助路線 – ng2user

回答

0

您正在收到該錯誤,因爲您沒有爲您設置爲第一條路線的「用戶」加載組件。 「用戶」的路線應該將主要的路由模塊中定義這樣

{ path: 'users', loadChildren: './users/user.module#UserModule' } 

和當前的代碼需要看起來像這樣

const userRoutes: Routes = [ 
    { 
    path: '', component: UsersComponent, children: [ 
     { 
     path: 'user-details', 
     outlet: 'list', 
     component: UserDetailsComponent 
     } 
    ] 
    } 

,這將讓杉杉路線「用戶」