Add route path aliases#1998
Conversation
|
It's funny because it's basically #542 😂 So I guess the main question is, how do you build the URL for one route vs the other? Something like this? About::Index.url #=> site.com/about
About::Index.with(locale: "nl").url #=> site.com/nl/about |
jwoertink
left a comment
There was a problem hiding this comment.
Honestly, the solution is pretty clean, and it looks like it still does cover being able to use the helpers like normal 😄
I'm trying to think of if there's any weird edge cases that might come up with it, but nothing is coming to mind...
So funny! 😄 I've never seen that issue, probably because it was before I discovered Lucky.
Precisely. That just works because it's using the There is one thing I'd like to add to simplify routing. Currently in the example above the About::Index.with(locale: nil).url #=> site.com/aboutIn case of localization, having this option would make it super easy to handle routing for the "main" locale (e.g. without |
Purpose
This PR adds the possibility to create aliases for route paths as discussed in #1996.
Description
I found another approach that is less invasive and requires a lot less changes to the code. It also doesn't affect performance when the feature is not used.
The way it works is to allow passing more than one path to the HTTP verb routing methods in actions:
The first path is still the “main” path, is required, and will set up the action. Any subsequent paths are just aliases and don't trigger the call setup. Every route is added through the
add_routemacro so the aliases have all the same features you'd expect, including prefixes, optional params, etc.I started using them in Fluck's website and they work great, so far without any side effects.
Checklist
crystal tool format spec src./script/setup./script/test