How do I render the main navigation menu? In Drupal 7, we were able to render the main navigation menu onto a page outside the main Drupal folders by including bootstrap.inc and displaying it with this code.

 $menuData = menu_tree_output(menu_tree_all_data('main-menu'));
 print drupal_render($menuData); 


Can something similar be done in Drupal 8?
Here is how to get the render Array :

  $menuService = \Drupal::service('menu.link_tree');
  $parameters = $menuService-&gt;getCurrentRouteMenuTreeParameters('main');
  $mainMenutree = $menuService-&gt;load('main', $parameters);
  $renderArray = $menuService-&gt;build($mainMenutree);


If needed, here is how to generate the HTML

$html = \Drupal::service('renderer')-&gt;render($renderArray);


Note : replace 'main' by menu name for another one.