Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to router.navigate to a route with an id placeholder inmidst the route url

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?

like image 659
Pascal Avatar asked Oct 03 '16 19:10

Pascal


1 Answers

Use template literals to form dynamic urls like this:

[`/departments/${id}/employees/assign`]
like image 198
Dave V Avatar answered Nov 15 '22 04:11

Dave V