I know we can set parameters in router paths using '/:id'. But I want to create an array of uncertain length like this: '/:id1/:id2/:id3/...'
Currently I'm managing up to three parameters like this:
const routes: Routes = [
    { path: '/:name1',  component: MyComponent,   canActivate: [ LocalUserGuard ] },
    { path: '/:name1/:name2',  component: MyComponent,   canActivate: [ LocalUserGuard ] },
    { path: '/:name1/:name2/:name3',  component: MyComponent,   canActivate: [ LocalUserGuard ] }
However I want to extend it to any number of parameters.
If you want it to be completely arbitrary, you could use a wildcard route:
const routes: Routes = [
  { path: '**', component: MyComponent, canActivate: [ LocalUserGuard ] },
]
Then inside MyComponent you can access the URL segments via the ActivatedRoute:
@Component({...})
export class MyComponent { 
  constructor(private route: ActivatedRoute) {
    route.url.subscribe((segments: UrlSegment[]) => {
      // do whatever you need to with the segments
    });
  }
}
See example Plunker: http://plnkr.co/edit/9YYMwO?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With