如何以编程方式将参数传递给angular2 +中的辅助路径? [英] How can I programmatically pass parameters to an auxiliary route in angular2+?
本文介绍了如何以编程方式将参数传递给angular2 +中的辅助路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用angular2,我想以编程方式在我的组件中打开一条辅助路线.
Using angular2, I want to open an auxiliary route programmatically in my component.
此代码使用列表"路径打开路由,并在正确的命名路由器出口中打开路由,但是我不确定如何将参数传递给路由:
This code opens the route with the 'list' path and it opens the route in the correct named router outlet, but I am not sure how to pass parameters to the route:
this.router.navigate(['./', { outlets: { 'list-outlet': 'list' } }]);
推荐答案
最后,我只需要使用一个数组来传递我的参数,请参见下面的param1
和param2
.
In the end, I just needed to use an array to pass my params... See param1
and param2
below.
this.router.navigate(['./', { outlets: { 'list-outlet': ['list', param1, param2]} }]);
注意...我必须在路由配置中更改路径:
Note... I had to change the path in my routing configuration:
{
path: 'list/:param1/:param2',
component: ClaimListComponent,
outlet: 'list-outlet'
}
然后在我的ngOnInit
函数中,我可以如Muirik所示将参数从路由器中拉出.
And then in my ngOnInit
function, I can pull the params out of the router as Muirik shows.
这篇关于如何以编程方式将参数传递给angular2 +中的辅助路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文