guru
guru

Reputation: 4022

Angular 4 - Adding router param before url

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.

Upvotes: 0

Views: 1408

Answers (3)

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.

Upvotes: 1

Daniel Segura Pérez
Daniel Segura Pérez

Reputation: 1117

try this:

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

or

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

Upvotes: 2

andrea06590
andrea06590

Reputation: 1299

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

Upvotes: 0

Related Questions