How to handle n number of parameter in Angular2/4 router?

156 Views Asked by At

In my application, there can be n number of params in the URLn and then it can have an optional following pattern too. For example, the URLs can be

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

How do I construct my routing module for these kind of URLs?

1

There are 1 best solutions below

2
Wesley Coetzee On

do you mean like so?

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