A. Gladkiy
A. Gladkiy

Reputation: 3450

Angular 2 remove params from url

I have /users page with list of users, I can click on Edit User button and see User details on this url /users/edit/1, when I save changes I want to highlight changed user. For that I use the following method:

gotoUsers(userId) {
    this.router.navigate(['../../', { id: userId }], { relativeTo: this.route });
}

And I see in url /users;id=1 and changed user is highlighted. If I want to edit other user again. And click on Edit button I see /users;id=1/edit/2

Click on Edit button:

gotoEditUser(userId: number) {
    this.router.navigate(['edit', userId], { relativeTo: this.route });
}

How can I remove ;id=1 param from url?

Upvotes: 1

Views: 2501

Answers (2)

A. Gladkiy
A. Gladkiy

Reputation: 3450

I've edited gotoEditUser method:

gotoEditUser(userId: number) {
    this.router.navigate(['../', 'users', 'edit', userId], { relativeTo: this.route });
}

But yet looking for the best solution for that.

Upvotes: 1

Raz Zelinger
Raz Zelinger

Reputation: 706

Because you use relativeTo: this.route in gotoEditUser the url starts from the current url witch is /users;id=1 you can see more information on this here: Assume relative navigation are being performed relative to the current activated route

Upvotes: 1

Related Questions