Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/actions/guides/http_and_routing/routing_and_params.cr
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,44 @@ class Guides::HttpAndRouting::RoutingAndParams < GuideAction
end
```

## Route aliases

Sometimes you may want to send more than one path to the same action. A
good use case, for example, are localized routes:

```
# Posts::Index in the default language
/posts

# also Posts::Index, but in an alternative language
/:locale/posts
```

To use route aliases, you can pass the paths as additional arguments:

```crystal
class Posts::Index < BrowserAction
get "/posts", "/:locale/posts" do
if locale = params.get?(:locale)
# locale == "nl"
else
# locale == nil
end
end
end
```

To access those routes in links, you can use both variants of the route
helpers as usual:

```crystal
Posts::Index.path
# => "/posts"

Posts::Index.with(locale: "nl").path
# => "/nl/posts"
```

## Routing style

By default Lucky ensures that all routes adhere to the same style. All
Expand Down