Skip to content

Commit 3f1bcb6

Browse files
committed
a named routes
1 parent 4e339ed commit 3f1bcb6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

_posts/2015-05-05-routes.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ If you want to be more riguros you can use something like:
5656
```java
5757
GET("/contact/{id: [0-9]+}", (routeContext) -> { ... });
5858
```
59+
60+
`Named` routes make referring to routes when generating redirects or URLs more convenient. You may specify a name for a route like so:
61+
62+
```java
63+
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")}).named("blog");
64+
```
65+
66+
Now, you may use the route's name when generating URLs or redirects:
67+
68+
```java
69+
Map<String, Object> parameters = ...
70+
routeContext.uriFor("blog", parameters);
71+
// or
72+
routeContext.redirect("blog", parameters);
73+
```

0 commit comments

Comments
 (0)