[英]angular2 and routing - adding a query parm to child
哇
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
如果我在下面的url我得到查询parm使用以下:
http://localhost:4200/#/services/(servicelistright:servicelist;type=11)
this.route.params.map(params => params['type'])
.subscribe(type => { console.log('stupid',type) });
嗯,我觉得这很棒......真棒......
但是我怎么添加查询parm呢?
1)使用router.navigate
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist']}}]);
我在哪里添加type = 11 ???
或者我的routerLink
<a md-raised-button routerLinkActive="['active']" [routerLink]="['/services']" ">Raised button</a>
参数以对象的形式传递给路径。 例如,要获取此查询字符串:
/inbox/33;details=true/messages/44;mode=preview
你需要使用以下数组:
['/inbox', 33, {details: true}, 'messages', 44, {mode: 'preview'}]
所以在你的情况下,你可以将type
param传递给router.navigate
:
this.router.navigate(['/services', {outlets: {'servicelistright': ['servicelist', {type: 11}]}}]);
在幕后, routerLink
只调用router.navigate
,因此您可以将相同的URL
字符串传递给指令:
<a [routerLink]="['/services', {outlets: {'servicelistright': ['servicelist', {type: 11}]}}]">Go</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.