# 4.7 Routes level interceptor

Routes level interceptor refers to the interceptors added in Routes. Below is an example:

/**
 * Backend routes
 */
public class AdminRoutes extends Routes {
 
  public void config() {
     // Here we configure the Routes level interceptor, multiple can be configured
     addInterceptor(new AdminAuthInterceptor());
 
     add("/admin", IndexAdminController.class, "/index");
     add("/admin/project", ProjectAdminController.class, "/project");
     add("/admin/share", ShareAdminController.class, "/share");
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

In the example above, AdminAuthInterceptor will intercept all action methods in IndexAdminController, ProjectAdminController, and ShareAdminController.

The functionality of Routes interceptors allows configuring the same interceptor for multiple Controllers with a single line of code, reducing code redundancy. The Routes level interceptor will be called before the Class level interceptor.

Last Updated: 9/17/2023, 6:05:19 AM