且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式将参数传递给 angular2+ 中的辅助路由?

更新时间:2022-05-05 22:43:05

最后,我只需要使用一个数组来传递我的参数...参见 param1param2 下面.

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.