Search code examples
scalaplayframework

PlayFramework: multiple routes file in project


Is that possible to have multiple conf/routes file in the play project? i.e:

   -> conf/ 
           routes
           utils.routes
           user.routes

Or is the are any work around for this? as I understand conf/routes will be compiled and validation will be run etc ..and would assume it is possible to override this logic somehow.


Solution

  • You can try to split it with the module approach as described in the official documentation.

    It’s also possible to split the route file into smaller pieces. This is a very handy feature if you want to create a robust, reusable multi-module play application.

    In a nutshell, you can group your app code into one or more modules, each with own route file(s). You can then include the smaller route files into the global route file like in the following example:

    conf/routes:

    GET /index                  controllers.HomeController.index()
    
    ->  /admin admin.Routes
    
    GET     /assets/*file       controllers.Assets.at(path="/public", file)
    

    modules/admin/conf/admin.routes:

    GET /index                  controllers.admin.HomeController.index()
    
    GET /assets/*file           controllers.Assets.at(path="/public/lib/myadmin", file)