[英]angular2 and routing - adding a query parm to child
Wow 哇
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
If I the below to the url I get get the query parm using the below: 如果我在下面的url我得到查询parm使用以下:
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? 但是我怎么添加查询parm呢?
1) by using router.navigate 1)使用router.navigate
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
where do I add type=11??? 我在哪里添加type = 11 ???
Or my routerLink 或者我的routerLink
<a md-raised-button routerLinkActive="['active']" [routerLink]="['/services']" ">Raised button</a>
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
: 所以在你的情况下,你可以将
type
param传递给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: 在幕后,
routerLink
只调用router.navigate
,因此您可以将相同的URL
字符串传递给指令:
<a [routerLink]="['/services', {outlets: {'servicelistright': ['servicelist', {type: 11}]}}]">Go</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.