问题
Wow
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
If I the below to the url I get get the query parm using the below:
http://localhost:4200/#/services/(servicelistright:servicelist;type=11)
this.route.params.map(params => params['type'])
.subscribe(type => { console.log('stupid',type) });
Well I think is just wonderful..wow great...
But how on earth do I add the query parm?
1) by using router.navigate
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
where do I add type=11???
Or my routerLink
<a md-raised-button routerLinkActive="['active']" [routerLink]="['/services']" ">Raised button</a>
回答1:
Parameters are passed to the route in a form of an object. For example, to get this query string:
/inbox/33;details=true/messages/44;mode=preview
you need to use the following array:
['/inbox', 33, {details: true}, 'messages', 44, {mode: 'preview'}]
So in your case you can pass the type
param like that to router.navigate
:
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist', {type: 11}]}}]);
behind the scenes, routerLink
just calls router.navigate
, so you can pass the same URL
string to the directive:
<a [routerLink]="['/services', {outlets: {'servicelistright': ['servicelist', {type: 11}]}}]">Go</a>
来源:https://stackoverflow.com/questions/42600241/angular2-and-routing-adding-a-query-parm-to-child