我有以下 routeConfig,此路由正常工作:
export const routeConfig: Routes = [
{path: '', redirectTo: 'use-cases', pathMatch: 'full'},
{path: 'use-cases', component: UseCasesComponent},
{path: 'add', component: AddComponent},
{path: '**', redirectTo: 'use-cases'},
];
如何为 use-cases/:id
添加路由?
我试过这个:
{path: 'use-cases', component: UseCasesComponent,
children: [
{
path: '/:id',
component: UseCaseComponent,
}
]
},
但它给我错误
异常:未捕获( promise ):[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)
最佳答案
不要在 path: '...'
中添加前导斜线
path: '/:id'
应该是
path: ':id'
关于angular - 如何使用 :id parameter in Angular2 创建子路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40288856/