Drupal 11: Show The Route Of The Current Page

Use the following to see the route of the current page.

/**
 * Implements hook_preprocess_page().
 *
 */
function mycustomtheme_preprocess_page(&$variables) {
  \Drupal::messenger()->addStatus(\Drupal::routeMatch()->getRouteName());
}

Add this to your theme file or a module file and clear the caches.

If you visit a page on this theme you will see a message being shown on the site. For example, the user profile page will show this.

entity.user.canonical

Add new comment

The content of this field is kept private and will not be shown publicly.