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.
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)
Building on top of javierhe's answer. If you are using a sbt single project and DI and still want to use multiple routes file, you can do so like below. No need of sbt multi project setup.
conf/
routes
admin.routes
conf/routes:
GET /index controllers.HomeController.index()
-> /admin admin.Routes
conf/admin.routes:
GET /index controllers.admin.HomeController.index()
And in the application loader, add below into build routes.
val adminRouter: admin.Routes = {
val prefix = "/"
wire[admin.Routes] //replace it with constructor if you do manual DI
}
val router: Routes = {
val prefix = "/"
wire[Routes] //replace it with constructor if you do manual DI
}
Tested with play 2.8.x and macwire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With