You can either use Simplify Menu Module and then you can render menu tree as an array in twig template like this
{% set items = simplify_menu('main') %}
{% for menu_item in items.menu_tree %}
<li>
<a href="{{ menu_item.url }}">{{ menu_item.text }}</a>
{% if submenuLevel1Item.description %}
<ul>
{% for sub_menu_item in menu_item.submenu %}
<li>
<a href="{{ sub_menu_item.url }}">{{ sub_menu_item.text }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
For more parameters kint(items)
OR (If you don't wish to install the module) you will need to preprocess menu items and pass it to the twig as Below
$menu_parameters = new \Drupal\Core\Menu\MenuTreeParameters();
// If you need to set depth of the tree
$menu_parameters->setMaxDepth(2);
// If you need only enabled links
$menu_parameters->onlyEnabledLinks();
$menus = \Drupal::menuTree()->load('Your Menu name', $menu_parameters);
$menuItems = [];
foreach ($menus as $key => $value) {
$menuUUIDArray = explode(':', $key);
$uuid = $menuUUIDArray[1];
$menuItem = [];
// If its a multi lingual site
$languageCode = \Drupal::languageManager()->getCurrentLanguage()->getId();
$menu_content = current(\Drupal::entityManager()->getStorage('menu_link_content')->loadByProperties(array('uuid' => $uuid)));
if ($menu_content->hasTranslation($languageCode)) {
$menu_content = $menu_content->getTranslation($languageCode);
}
$url = $menu_content->getUrlObject();
$menuItem['title'] = $menu_content->get('title')->value;
$menuItem['link'] = ($url->toString() == '') ? '#' : $url->toString();
$menuItem['weight'] = $menu_content->get('weight')->value;
if ($value->hasChildren) {
$subTreeArray = $value->subtree;
foreach ($subTreeArray as $key => $child) {
}
// use foreach OR recursion to get the values
$menuItem['children'] = ......
}
$menuItems = $menuItem;
}