如何在 Angular2 中使用 :id 参数创建子路由

3 angular2-routing angular

我有以下路线配置,该路线正常工作:

export const routeConfig: Routes = [
    {path: '', redirectTo: 'use-cases', pathMatch: 'full'},
    {path: 'use-cases', component: UseCasesComponent},
    {path: 'add', component: AddComponent},
    {path: '**', redirectTo: 'use-cases'},
];
Run Code Online (Sandbox Code Playgroud)

如何添加路线use-cases/:id

我已经尝试过这个:

{path: 'use-cases', component: UseCasesComponent,
    children: [
        {
            path: '/:id',
            component: UseCaseComponent,
        }
    ]
},
Run Code Online (Sandbox Code Playgroud)

但这给了我错误

异常:未捕获(承诺):[object Object]

Error: Uncaught (in promise): [object Object]
    at resolvePromise (http://localhost:3000/polyfills.bundle.js:15073:32)
    at http://localhost:3000/polyfills.bundle.js:15050:14
    at ZoneDelegate.invoke (http://localhost:3000/polyfills.bundle.js:14837:27)
    at Object.onInvoke (http://localhost:3000/vendor.bundle.js:7133:42)
    at ZoneDelegate.invoke (http://localhost:3000/polyfills.bundle.js:14836:33)
    at Zone.run (http://localhost:3000/polyfills.bundle.js:14719:44)
    at http://localhost:3000/polyfills.bundle.js:15107:58
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.bundle.js:14870:36)
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 6

不要添加前导斜杠path: '...'

 path: '/:id'
Run Code Online (Sandbox Code Playgroud)

应该

 path: ':id'
Run Code Online (Sandbox Code Playgroud)