本文介绍了如何以编程方式将参数传递给 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+ 中的辅助路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!