0

Just wondering whether there is a way to create a angular route with parameter before of in-between a url,

{path: ':param/test/list'} or {path: 'web/:param/list'}

and reference it in routerLink directive,

[routerLink]="['test/list', paramValue]"

Thee parameter value is always getting appended to the end of the url.

guru
  • 4,002
  • 1
  • 28
  • 33

3 Answers3

2

try this:

path: { ':parameter/test/list' }
[routerLink]="[paramValue + 'test/list']"

or

path: { 'test/:parameter/list' }
[routerLink]="['test/' + paramValue + '/list']"
1

You should put parameter segment in same position to route. Something similar:

path: { ':parameter/test/list' }
[routerLink]="[paramValeu, 'test', 'list']"

Edit:

Separate segments in Route link.

  • Thanks Martin. When I do this the '/' in the URL 'test/list' gets replaced with '%2F' which is the encoding reference for the slash character. Like - 'paramValue/test%2Flist – guru Nov 17 '17 at 10:12
  • Well maybe you need to change route link: [routerLink]="[paramValeu, 'test', 'list']. Because route link use the route segments separate. – Mauricio Wanderley Martins Nov 17 '17 at 11:49
0

I think this could help :) How to pass a parameter to routerLink that is somewhere inside the URL?

Always better to use router instead of [href]

Good luck

andrea06590
  • 1,259
  • 3
  • 10
  • 22