1

I'm using Angular (4) with the @angular/router and want to be able to have optional parameters in a path style.

I currently have this:

{ path: 'cars', component: CarComponent },
{ path: 'cars/:type', component: CarComponent },
{ path: 'cars/:type/:brand', component: CarComponent },
{ path: 'cars/:type/:brand/:id', component: CarComponent },

This works but what I'm looking for is an optional parameter in :type. The type can either be 'new' or empty so ' ' and the empty part is the one that seems hard to do because Angular doesn't know what the context is.

Help would be appreciated

myst1c
  • 593
  • 3
  • 13
Ronald
  • 69
  • 8
  • Have you looked at this thread? https://stackoverflow.com/questions/34208745/angular-2-optional-route-parameter – Carbosound1 Sep 25 '17 at 19:43

1 Answers1

0

You are doing RESTful conceptually wrong. /cars would take you to a list of cars where you can filter by type or brand. /cars/:id would take you to the car that you selected from the list.

mruanova
  • 6,351
  • 6
  • 37
  • 55