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?

1 Answer 1

21

Optional route parameters are marked with ?, like this:

`/users/:id?`

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

Sign up to request clarification or add additional context in comments.

3 Comments

With Angular 1.3.4 I'm getting this error when I try that: Error: Invalid parameter name '' in pattern '/users/:id?'
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 this is not for ui-router. In ui-router you shall use query string /users?id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.