Introduction to Play routes
All the supported routes are specified within a single file: routes (by default). This makes it all the easier to figure out which one would be ideal.
The routes file is compiled and if any errors occur, the compilation fails.
However, the routes file is not a Scala object. So how does the compiler know what to do with the routes file? To find this out, let's perform the following steps:
Let's create a project that displays a Hello, World! page. Now, define the
index.scala.htmlhome page as follows:<!DOCTYPE html> <html> <head> <title>Home</title> </head> <body> <h1>Hello, World!</h1> </body> </html>We will use this in our controller in this way:
package controllers import play.api.mvc._ object AppController extends Controller { def index = Action { Ok(views.html.index()) } }All we need to view our page is an entry in the
routesfile:# Home page GET ...