Skip to content

Commit 63841b0

Browse files
committed
Resolve #44
1 parent c7e2148 commit 63841b0

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

_posts/2015-05-05-routes.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ If you specify your parameter <u>without</u> a regex pattern, like the third exa
110110
across a large number of routes without needing to define this attribute on each individual route.
111111
Also you can add (route) filters for all routes of the group.
112112

113+
The `RouteGroup` is a concept very import when you are forced to deal with a considerable number of routes in your application.
114+
113115
The below snippet defines a `UserRoutes` group:
114116

115117
```java
@@ -146,6 +148,40 @@ public class PippoApplication extends Application {
146148

147149
You can access the routes defined in `UserRoutes` using something like `http://localhost:8338/user/1` (retrieve the user with _id_ equals with 1).
148150

149-
You can see a more complex example in [Matilda](https://github.com/decebals/matilda/blob/master/src/main/java/ro/fortsoft/matilda/PippoApplication.java#L108) (a real life application built with Pippo).
150-
151+
Pippo has support for __NESTED GROUPS__.
152+
The idea is that you can create completely decoupled routes groups. Using nested routes groups you can create a nice modular application.
153+
154+
```java
155+
class DemoApplication extends Application {
156+
157+
@Override
158+
protected void onInit() {
159+
addRouteGroup(new AdminRoutes());
160+
}
161+
162+
}
163+
164+
class AdminRoutes extends RouteGroup {
165+
166+
public AdminRoutes() {
167+
super("/admin");
151168

169+
// BEFORE FILTERS
170+
addBeforeFilters();
171+
172+
// ROUTES
173+
addRoutes();
174+
175+
// GROUPS
176+
addRouteGroup(new UserRoutes());
177+
addRouteGroup(new CustomerRoutes());
178+
}
179+
180+
}
181+
```
182+
183+
In above snippet I added (in DemoApplication) `AdminRoutes` as route group which contains `UserRoutes` and `CustomerRoutes` as child routes groups.
184+
I don't need to know when I create a RouteGroup where the group will be mount. For example I can have a modular web application where each plugin comes with own independent routes (user management -> `UserRoutes`, customer management -> `CustomerRoutes`).
185+
186+
You can see a more complex example in [Matilda](https://github.com/decebals/matilda/blob/master/src/main/java/ro/fortsoft/matilda/PippoApplication.java#L108) (a real life application built with Pippo).
187+

0 commit comments

Comments
 (0)