5

I have a URL in my app.js containing routes. lets say the url is:

/api/:opt1/:opt2/:opt3/users

I want that my url will work in any case, i should able to ignore the optional parameters (opt1, opt2 or opt3, may be all or few). How can I achieve this.

Is there any way that I can call $location.path('/users'), and I can specify also what are the values of the optional parameters?

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
shyam
  • 65
  • 1
  • 3

1 Answers1

21

Optional route parameters are marked with ?, like this:

`/users/:id?`

Then this route matches both /users and /users/1 paths

karaxuna
  • 26,752
  • 13
  • 82
  • 117
  • With Angular 1.3.4 I'm getting this error when I try that: `Error: Invalid parameter name '' in pattern '/users/:id?'` – Martyn Chamberlin Mar 17 '15 at 22:31
  • Not working for me...Do i need some module/library?.. I am using ui-router? I also tried adding ngRoute but still no result – Sami Nov 25 '15 at 11:41
  • @Sami this is not for ui-router. In ui-router you shall use query string `/users?id` – karaxuna Nov 25 '15 at 12:25