Skip to content
July 14, 2012 / edeustace

Adding routes programmatically to Play 2.* apps

There’s some discussion about how one can programmatically add routes to a Play 2.* app. It appears that you can’t add them to the generated Routes class, but you can handle the web requests yourself by overriding ‘onRouteRequest’.

<code>override def onRouteRequest(request: RequestHeader): Option[Handler] = {
  //do our own path matching first - otherwise pass it onto play.
  request.path match {
    case "/injectedRoute" => Some(controllers.Application.customRoute)
    case _ => Play.maybeApplication.flatMap(_.routes.flatMap {
      router =>

Here’s an example on github:

See this question too:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: