Module Development

Create a Route for the Weather Page for Drupal 8, 9, and 10

Routes map URLs to the code that generates the content for display. As module developers, we create routes whenever we want to add a new URL with code. Our task is to create a route for a page displaying the weekend weather forecast. We start by defining the route, then add the corresponding controller.

In this tutorial, we'll:

  • Create a routing YAML file for a custom weather page.
  • Define a route instructing Drupal to point the path /weather to our custom code.

By the end of this tutorial, you will have defined a route for your weather page, including the path and a reference to the controller managing the content.

Drupal Module Developer Guide