Angular routerLink附加路由而不是替换



我的Angular应用中有以下路由配置

...
{ path: 'item/new', component: ItemDetailsComponent, pathMatch: 'full', data: { new: true } },
{ path: 'item/:id/:action', component: ItemDetailsComponent, pathMatch: 'full' },
...

:动作可以是";视图";或";编辑";。当我直接在浏览器中输入这三条可能的路径时,它们都能工作。然而,项目模板中的路由器链接不:

<div routerLink="['/item', id, 'edit']">Test</div>

"id";是在组件中设置的,所以这可能不是问题所在。浏览器控制台错误表明url以某种方式被附加:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'item/2/view/%5B'/item',%20id,%20'edit'%5D'
Error: Cannot match any routes. URL Segment: 'item/2/view/%5B'/item',%20id,%20'edit'%5D'

由于路由器链接确实是以斜杠开头的,所以我希望它能起作用。

u应该使用

<div [routerLink]="['/item', id, 'edit']">Test</div>

<div routerLink="/item/{{id}}/edit">Test</div>

最新更新