Module Development

Add a Parameter to a Route for Drupal 8, 9, and 10

Route parameters enable a single route and controller to handle multiple URLs by passing dynamic values from the URL to the controller. This allows for more versatile and responsive page content generation.

In this tutorial, we'll:

  • Understand the function of route parameters.
  • Update the anytown.weather_page route to include parameters.
  • Modify the WeatherPage controller to use these parameters.

By the end of this tutorial, you'll know how to use route parameters to pass dynamic values to controllers.

Drupal Module Developer Guide