Reputation: 12885
I have a route url like:
/departments/:id/employees/assign'
When I navigate to the above url:
this._router.navigate(['/departments/:id/employees/assign', id]);
Then angular is always appending the passed id to the end of the url, but that is not what I want.
When I try this
this._router.navigate(['/departments/:id/employees/assign', {id: id}]);
I get this url in the browser:
http://localhost:4200/departments/%3Aid/employees/assign;id=1
I want the url to be in the browser: /departments/1/employees/assign
What do I have to change?
Upvotes: 6
Views: 18974
Reputation: 1976
Use template literals to form dynamic urls like this:
[`/departments/${id}/employees/assign`]
Upvotes: 6
Reputation: 61
According to doc https://angular.io/docs/ts/latest/api/router/index/Router-class.html, you should choose either to user navigateByUrl :
router.navigateByUrl("/departments/:id/employees/assign");
or split the components of the url in parts :
router.navigate(['departments', 1, 'employees', assign], {relativeTo: route});
Upvotes: 6