Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Routing with URL having optional parameters

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?

like image 255
shyam Avatar asked Apr 12 '14 07:04

shyam


1 Answers

Optional route parameters are marked with ?, like this:

`/users/:id?`

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

like image 113
karaxuna Avatar answered Oct 06 '22 01:10

karaxuna