Creating Routes

In web applications, routes are what connect URLs (web addresses) with code that needs to be executed to return a result - usually a web page.

When you define a route, you'll provide an URL (such as /example) and connect it to a callback method on a controller class (such as MyController::BuildExamplePage()) that will be executed when someone visits that URL.

Route callback methods are typically responsible for generating and returning web pages, but you can also configure them to do things like:

  • trigger a file download
  • show a form
  • start a process
  • log someone out
  • redirect someone
  • return an HTTP status code such as 404 (Page Not Found)
  • ...

Routes are an integral part of every web application framework. In this section you'll learn how Drupal uses routes and how you can create your own routes and link them to your own controllers.