有角度的路由器。如何使用不同的参数导航到当前 URL?

Cri*_*aza 4 javascript url-routing typescript angular

我有一个 Angular 5 项目,用户在单击某个项目时会导航到这样的路线。

my_domain/{account_id}/item/{item_id}/open/
my_domain/{account_id}/item/{item_id}/closed/
my_domain/{account_id}/item/{item_id}/snoozed/
Run Code Online (Sandbox Code Playgroud)

用户应该能够更改 account_id 或 item_id。所以我希望能够重新加载页面,仅更改参数(id)。我怎样才能做到这一点?

nek*_*bit 6

角8

.component.ts
中 ,您可以使用当前 url 并将参数放入导航数组

this.router.navigate([this.router.url, 'open']);
Run Code Online (Sandbox Code Playgroud)

或者在.component.html
中 您可以使用点作为 url“./youparam”的一部分 - 在这种情况下“./”==当前 url

< a [routerLink]="['./open']">open</a>
Run Code Online (Sandbox Code Playgroud)