How to specify request parameters using routerLink directive

I am experimenting with a new router (version 3.0.0-alpha.7) and would like to know how to specify request parameters using the routerLink directive?

The Router.navigate () method below generates a URL, for example http: // localhost: 3000 / component-a? X = 1

this.router.navigate(['/component-a'], {queryParams: {x: 1}}); 

However, I cannot figure out how to do the same with the routerLink directive. A template like the one below returns a parser error ...

 <a [routerLink]="['/component-a'], {queryParams: {x: 1}}">Component A</a> 

And the closest I can get is http: // localhost: 3000 / component-a; x = 1 , which uses the syntax for the child route.

 <a [routerLink]="['/component-a', {x:1}]">Component A</a> 
+5
source share
2 answers

You can do something like this

 <a [routerLink]="['/component-a']" [queryParams]="{x: 1}">Component A</a> 
+12
source

In the new router component, you can do this as follows:

Passing parameter in URL:

 <a [routerLink]="['/component-a', 1]">Component A</a> 

Passing the request parameter:

 <a [routerLink]="['/component-a', { x: 1 }]">Crisis Center</a> 
0
source

All Articles