The idea is that we add a new named method on RouteGroup similar with the same method from Route.
Show me the code:
// create the group with a name
RouteGroup group = new RouteGroup("/users").named("users.");
// add routes for group
group.GET("/", ...).named("getAll");
group.GET("/{id}", ...).named("get");
group.PUT("/{id}", ...).named("update");
group.DELETE("/{id}", ...).named("delete");
// add route group to application
addRouteGroup(group);
The idea is that the route name is prefixed automatically with the group name.
Now, you may use the route's name when generating URLs or redirects:
Map<String, Object> parameters = ...
routeContext.uriFor("users.getAll", parameters);
routeContext.uriFor("users.get", parameters);
routeContext.uriFor("users.update", parameters);
routeContext.uriFor("users.delete", parameters);
// the same for redirect
routeContext.redirect("users.getAll", parameters);
...
In my example I used . as separator but you can use any character or string.
What you think?
The idea is that we add a new
namedmethod onRouteGroupsimilar with the same method fromRoute.Show me the code:
The idea is that the route name is prefixed automatically with the group name.
Now, you may use the route's name when generating URLs or redirects:
In my example I used
.as separator but you can use any character or string.What you think?