-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
More Flexible Routing via optional/unordered params. inc.. example. #3705
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
Comments
Isn't that what query strings are for? |
khepin, please clarify what your referring to? Do you have a link or a doc reference please? |
http://en.wikipedia.org/wiki/Query_string because it seems you're really trying
|
@khepin yeah, sorry i thought you meant SF2 supported that in the proper route format, i don't like the whole ?page=2&month=6 aspect of it, thats very old school these days. It would definitely be inconsistent with what the rest of the site has. I feel this kind of flexibility is essential to many modern web apps, and i don't think i am the only one who would like to see this supported as i see other people asking similar questions on the IRC room. Thought just to clarify when i said unordered, i mean if an optional param is missing, then the next param moves one to the left in order to form a proper route match. |
I have an idea for how this could work, if a Route object had its pattern as an array instead of a string, the SF2 route compiler could convert the route with optional params into multiple patterns, that way they all can match, while still appearing as a single route. The major benefit being that you would not have to change much in the route pattern matching algorithm other than match for each pattern in the array. And being cached would have little impact on performance of the SF2 router. It could be a 2.2 release feature. |
@codeconsortium it's not very old school. It's how URLs are supposed to be. There is a resource ( |
@Seldaek to be more precise, its not very Web 2.0 then. Most modern frameworks promote the feature of friendlier urls vs query strings and it seems like a regression to my to go back to QS. The possible solution i provided above though could work by the route containing the pattern as an array of compiled combinations. I guess this is done during the cache warming process. That way a route can match various parameters according to the compiled list of patterns. Just a thought, its one of the big things about SF2 that so much is cached to optimise performance. It would take out the complexity of trying to test overly complex patterns at runtime. |
It's not about Web 2.0 or not, most older "modern" frameworks promoted this because they misunderstood it, because RewriteRules were the new cool thing to have and abuse, but the modern modern frameworks do not promote this because it does not make sense in terms of HTTP / REST URL design. |
Agree with @Seldaek |
I didn't want to say you are doing it wrong and that what you are trying to achieve would be better done via qs. |
Agree with @Seldaek too, |
Closing this issue because, besides the philosophical discussion about paths vs query strings, what is proposed would be very difficult to implement without having many non-intuitive behaviors and it would introduce easy to miss colliding routes. |
The routing in SF2 could do with being more flexible in terms of both the number of optional params included and and the order in which they are found if one or more are missing.
Optional parameters in SF2 routes is implemented as {value} however if a slash follows this you have empty value of null and a url with 2 slashes in it which is not a good looking url.
I am often having to have 2 routes for pages with pagination, one route without the pagination and one with, namely because of the word /page being before the number which looks funky if no value follows it. Example:
Unfortunately, that means if i wanted a filtered blog without the page number i have to have /blog/page//month/3 etc but it would be better if i could have /blog/month/3 and /blog/page/2/month/3 for example. The only way around this now is multiple routes for the same thing:
Depending on the number of variables, the variations would increase exponentially to encompass each combination of variables.
Routes would be better if we could group the label with the parameter and make them optional to the degree that we do not need 2 slashes ontop of each other. To emphasise the optionality of a route, we should be able to put them in square brackets (e.g [/optional/{param}] ), like so:
Which also allowed us to remove an item from the first example, and 3 from the second example. The number of routes we can decrease by grows by the number of the number of combinations we need.
This is all useful for pages with varying degrees of parameters that are optional a user may wish to filter page results by.
The text was updated successfully, but these errors were encountered: