Reputation: 15034
In my angular 2 SPA application , I have defined one of my routes as mentioned below
{path:'acategories/:id/products/:pid' , component:ProductComponent}
To use the above route I have defined a routerLink in my template as below
<a [routerLink]="['acategories' , product.category , 'products' , product._id ]"> Product </a>
But the above routerLink does not generate the link as expected?
I was expecting http://localhost:3000/acategories/books/products/1 but instead it was http://localhost:3000/acategories/books/products/acategories/books/products/1
What needs to be modified in the routerLink ?
Upvotes: 1
Views: 657
Reputation: 40647
Your link needs to be:
<a [routerLink]="['/acategories' , product.category , 'products' , product._id ]"> Product </a>
"/" indicates that this is a full(absolute) path, if you don't include it, it will be relative like the one you are getting.
Upvotes: 2