简体   繁体   中英

Play framework routes

I want to catch all unkown GET operations.

My routes file looks like this:

GET     /                       controllers.MainController.index()
#All other routes

#finally
GET     /[^/]+/                 controllers.MainController.fault()

The final GET definition is at the bottom on the list because of the priority given to the above get operations, otherwise all requests would be true to the /[^/]+/ condition.

The problem is that it goes to the default catch page saying 'Action not found'

How can I catch all routes?

I believe

GET  /*route controllers.MainController.fault()

would work better. route will capture the path that was received, you can pass it as an argument to your fault method.

But, I would suggest another alternative: you can implement a GlobalSettings object where you override the method

def onHandlerNotFound(request: RequestHeader): Future[SimpleResult]

This method will be called each time you get a request for which it was not possible to find a proper handler. You can find more information here: http://www.playframework.com/documentation/2.2.x/ScalaGlobal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM