如何在Angular2 / 4路由器中处理n个参数?

时间:2017-04-06 11:40:24

标签: angular angular-ui-router angular2-routing angular2-router angular2-router3

在我的应用程序中,URLn中可以有n个参数,然后它也可以有一个可选的跟随模式。 例如,URL可以是

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}

如何为这类URL构建路由模块?

1 个答案:

答案 0 :(得分:0)

你的意思是这样吗?

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}
])