質問

Is there a default catch all fallback route in Play framework? If so how can I configure it in my routes file? Currently, there are some urls that I do not want the user to call them and even if they call, I don't want that error page appearing, rather I want them to go to the landing page of my web app! Is there a way to do that in the routes configuration file?

役に立ちましたか?

解決

Simply define a route matching any path at the end of your routes file. Do not forget to define specific routes for your assets though, for example:

GET   /               controllers.Application.index
GET   /some/path      controllers.Application.someHandler
...

# End of file
GET   /favicon.ico    controllers.Assets.at(path="/public", file="img/favicon.ico") 
GET   /$file<(css|img|js|partials)/.*>    controllers.Assets.at(path="/public", file) 
GET   /$path<.*>      controllers.Application.catchall(path)

Any URL not matched by an earlier rule will be matched by this one.

他のヒント

Catch all routes makes sense when you want to do something with the path (ie. resolve it manually in your custom action), otherwise it's enough to use common onHandlerNotFound in your Global object and redirect request wherever you want.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top