1

I need to register to a state, a route where the parameters has a prefix and a slash (route/to/parPrefix1/:paramValue1/parPrefix2/:paramValue2) and these parameters are all optional, so if the parameter1 is not set, the resulting url should be: route/to/parPrefix2/value2

How can I handle this case?

Then I have a second issue: the date should be specified like this: 20/10/2015 If i solve the first point I could set a parameter per date part, however, is there a more elegant solution?

a real case url: /risultati/destinazioni/:destinations/localita/:locations/partenza/:startingDate/ritorno/:returningDate/adulti/:adults/bambini/:children/eta/:childrenAges/aeroporti/:airports/flessibile/:flexDate/

2 Answers 2

1

You most likely need to set up multiple routes, that point to the same view:

ex:

route/to/parPrefix1/:paramValue1
route/to/parPrefix1/:paramValue1/parPrefix2/:paramValue2
Sign up to request clarification or add additional context in comments.

4 Comments

what if the missing parameter is the second one? I've up to 9 optional parameters, should I have to register all the permutations?
After looking over this link github.com/angular-ui/ui-router/issues/108 it looks like you may be able to do something like the following: /route/to/[parPrefix1/:paramValue1[paraPrefix2/:paramValue2]]
I can't make your example work, I red that page, and I think this was just an implementation suggestion..
Hm ok... Well my only suggestion is be smarter with your URLs to avoid having so many possible routes. Limit it to 2-3 parameters in the URL and the remainder (like date) are in the query string
0

I agree with spanndemic, see http://benfoster.io/blog/ui-router-optional-parameters. Also I think that most of that data should be passed via services or values. Such a long url will always make things much more difficult.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.