Topic

Routes

Last updated August 18, 2017

When a user visits a particular URL on a Drupal site, the path they are visiting is a route. Drupal's routing system helps figure out which controller is responsible for responding to the route being requested. Drupal matches the incoming request's path to a controller by looking through the routes that have been registered in active modules.

Example tasks

  • Create your own routes in custom modules
  • Understand how Drupal's routing system maps paths to controllers

Confidence

At this point in the development cycle of Drupal 8 the routing system is relatively stable. This is mainly because Drupal's routing system leverages the Symfony routing component.

Drupalize.Me resources

  • Create a Module with a Route and Controller

    • This tutorial will help get you started with a simple module that defines a route and a controller.
  • Add a Menu Item

    • This tutorial walks you through creating a menu item in custom code. A part of this process is defining a route for the menu item. Also see the subsequent Action, Contextual and Local Task link tutorials for further route examples.
  • Create a custom content entity

    • This tutorial walks through the process of creating a custom content entity. Since there are several url paths that will display various types of information about our custom entity there are multiple examples of registering routes in this tutorial as well.

More Guides

We have guides on many Drupal skills and topics.

Explore guides

External resources

  • Routing system overview (drupal.org)

    • The main entry point for Drupal's official documentation about the routing system.
  • Symfony's routing component (symfony.com)

    • The official documentation for the Symfony routing component that Drupal's routing system is based on.
  • Structure of routes (drupal.org)

    • This page in particular covers the variety of configuration options that make up routing configuration files.
  • Examples project's page_example module (cgit.drupalcode.org)

    • The Examples project contains many sub-modules that demonstrate various Drupal sub-systems through well-documented code. To learn more about how routing and controllers work, take a look at the page_example module here.