Angular 4 router %2F symbols in path

Viewed 3656

There is some problem with angular4 router.

I have created a list of menu items and i got object from back-end for router link creation, but if menuItem.link equals to mypath/example it will be replaced by angular to mypath%2Fexample if i clicked in this item.

So routing is not working because it cannot match any routes, because i have defined it for (mypath/example)

<a [routerLink]="['/', menuItem.link, menuItem.id]" routerLinkActive="active_link">

I have tried to add /* to router link but it still not working. Thanks for your answers.

2 Answers

When you use routerLink as an array like this:

<a [routerLink]="[var1, var2]">title</a>

It will URLEncode each member of the array. This is expected behavior because it assumes you would pass each variable as route or child.

If you don't want this, pass it as a string.

<a [routerLink]="var1 + var2">title</a>
Related