0

What I would like to do is simply following:

@RouteConfig([
    { path: '/user/:id', component: User, name: 'User' },
    { path: '/user', component: User, name: 'User' }
]);

As you can see, that :id is optional. Somehow I get the feeling that this code example can be shortened, something like this:

@RouteConfig([
    { path: '/user/:id?', component: User, name: 'User' }
]);

BTW, this doesn't work, but it should express what I'm thinking. Is something like this possible?

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
  • Does this answer your question? [Angular 2 optional route parameter](https://stackoverflow.com/questions/34208745/angular-2-optional-route-parameter) – JSON Derulo Mar 10 '23 at 11:58
  • I saw that post too, its a bit old and the solution provided there are all inline with my first code example. – Jeanluca Scaljeri Mar 10 '23 at 12:39
  • As far as I know, nothing changed in this regard, so the answers are still up-to-date. Also there are alternative answers, for example the one with the redirect. – JSON Derulo Mar 10 '23 at 12:59

0 Answers0