Srini Srini - 3 months ago 6
Scala Question

How to do reverse routing from subcontroller to the sub routes in play scala?

I have created the sub routes from main route and I have created the subcontroller package e.g controllers.subcontrollers. Now how to access my sub routes from sub controllers.

Trp Trp
Answer

You can access by using this:

// Redirect to /hello/Bob
def helloBob = Action {
  Redirect(routes.Application.hello("Bob"))
}

As you can see in the playframework documentation.

https://playframework.com/documentation/2.3.x/ScalaRouting

But, if you meant that you have multiples controllers and divided them into packages and want to access them inside another another controller. You can achieve it using something like this:

controllers.packageName.routes.ControllerName.functionInsideController