Skip to main content
2 of 2
this will not work unless it is identified as external and has a uri

routing.yml are routes of your site, so they can not be external.

links.menu.yml are links that point to routes, so they can not be external.

To create external links, you need to create them as a menu link content entity in your hook_install() function.

Something like this:

  $menu_link = MenuLinkContent::create(array(
      'title' => 'Link title',
      'link' => ['uri' => 'https://www.example.com'],
      'menu_name' => 'navigation',
      'weight' => 0,
      'external' => TRUE,
      'bundle' => 'menu_link_content',
    ));
  $menu_link->save();
Berdir
  • 83.5k
  • 6
  • 161
  • 207