Skip to content

Optional route parameters with prefix #2061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paolosanchi opened this issue Jun 24, 2015 · 6 comments
Closed

Optional route parameters with prefix #2061

paolosanchi opened this issue Jun 24, 2015 · 6 comments

Comments

@paolosanchi
Copy link

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/

I red this issue, but it seems that my case is not handled.. am I right?:
#108

(I've post this here too: http://stackoverflow.com/questions/31006196/optional-route-parameters-with-prefix-angular-ui-router)

@eddiemonge
Copy link
Contributor

For the date, why not use dashes? And maybe use dashes where you think you have to use slashes?

@paolosanchi
Copy link
Author

yep, I could do it, but I have to maintain the retrocompatibility with the old urls..
Anyway, I've looked to the implementation of the UrlMatcher and figured out that there is no way to archive what I need, due to what is explaind in the documentation to.
So I had to add a new config to the params: prefix
I add a third way to automatically parse the prefix using the char before the prefix '!':

route/to/!parPrefix1/paramValue1/!parPrefix2/paramValue2

If anyone is interested I can make a fork

@eddiemonge
Copy link
Contributor

Doesn't that then break the old urls since you are adding new characters?

@paolosanchi
Copy link
Author

it breaks the segment starting with ! because it recognize them as prefix of the following parameter..
Anyway.. it's just a shortcut to se the prefix setting in the value..
with my implementation you can set the parameters like this:

url: "route/to/parPrefix1/:param1/parPrefix2/:param2",
params: {
param1: {
value: "",
squash: true,
prefix: parPrefix1: "",
},
param2: {
value: "",
squash: true,
prefix: parPrefix2: "",
},
}

this way if the param1 has the default value, the parPrefix is squashed too..

I'm going to commit my changes.. and omitting the part of the ! placeholder

@paolosanchi
Copy link
Author

@eddiemonge
Copy link
Contributor

Closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants