如何在Angular2/4路由器中处理n个参数?
问题描述:
在我的应用程序中,URLn中可以有n个参数,然后它也可以有一个可选的跟随模式。 例如,URL可以是如何在Angular2/4路由器中处理n个参数?
http://example.com/{param1}
http://example.com/{param1}/constant/{id}
http://example.com/{param1}/{param2}/constant/{id}
http://example.com/{param1}/{param2}
http://example.com/{param1}/{param2}/{param3}
http://example.com/{param1}/{param2}/{param3}/constant/{id}
etc
如何为这些类型的URL构建我的路由模块?
答
你是这个意思吗?
RouterModule.forChild([
{ path: 'api/whatever/:id1/', component: ComponentName}
{ path: 'api/whatever/:id1/dosomething/:id2', component: ComponentName}
{ path: 'api/whatever/:id1/:id2', component: ComponentName}
{ path: 'api/whatever/:id1/:id2/dosomething/:id3/dosomemore', component: ComponentName}
])
就是这样的,是的。但是:id1 /:id2并不总是:id1 /:id2,它可能是:id1 /:id2 /:id3 /..../ idn – user1532043
因此,您希望能够指定不定数量的id?这从我所知道的是不可能的。你需要按照我的例子来指定每条路线。我不太确定你想通过这种方式实现什么,如果你给我一个例子,我可以建议一种替代方法? –