Custom classes for menu links How can I add custom classes for links into main menu in Drupal 8. This is template for my main menu called menu--main.html.twig

{% import _self as menus %}
{{ menus.menu_links(items, attributes, 0) }}

{% macro menu_links(items, attributes, menu_level) %}
  {% import _self as menus %}
  {% if items %}
    {% if menu_level == 0 %}
        &lt;ul{{ attributes.addClass('main-nav') }}&gt;

        {% for item in items %}
        &lt;li{{ item.attributes.addClass('main-nav__item') }}&gt;
            {{ link(item.title, item.url) }}
            {% if item.below %}
                {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
            {% endif %}
        &lt;/li&gt;
        {% endfor %}
    {% else %}
        &lt;ul class="main-nav__sub js-nav-submenu "&gt;

        {% for item in items %}
        &lt;li{{ item.attributes.addClass('main-nav__sub-item') }}&gt;
            {{ link(item.title, item.url) }}
            {% if item.below %}
                {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
            {% endif %}
        &lt;/li&gt;
        {% endfor %}
    {% endif %}
    &lt;/ul&gt;
  {% endif %}
{% endmacro %}


And I need to achieve this result:

&lt;ul class="main-nav"&gt;
  &lt;li class="main-nav__item"&gt;&lt;a class="main-nav__link main-nav__link--active" href="index.html"&gt;Úvod&lt;/a&gt;&lt;/li&gt;
  &lt;li class="main-nav__item"&gt;&lt;a class="main-nav__link js-nav-submenu-toggler" href="#"&gt;O škole&lt;/a&gt;
    &lt;ul class="main-nav__sub js-nav-submenu"&gt;
      &lt;li class="main-nav__sub-item"&gt;&lt;a class="main-nav__sub-link" href="#"&gt;Aktuality&lt;/a&gt;&lt;/li&gt;
      &lt;li class="main-nav__sub-item"&gt;&lt;a class="main-nav__sub-link " href="pedagogovia.html"&gt;Pedagógovia&lt;/a&gt;&lt;/li&gt;
      &lt;li class="main-nav__sub-item"&gt;&lt;a class="main-nav__sub-link" href="#"&gt;Dokumenty&lt;/a&gt;&lt;/li&gt;
      &lt;li class="main-nav__sub-item"&gt;&lt;a class="main-nav__sub-link " href="historia.html"&gt;História&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li class="main-nav__item"&gt;&lt;a class="main-nav__link" href="#"&gt;Informácie o štúdiu&lt;/a&gt;&lt;/li&gt;
  &lt;li class="main-nav__item"&gt;&lt;a class="main-nav__link" href="#"&gt;Fotogaléria&lt;/a&gt;&lt;/li&gt;
  &lt;li class="main-nav__item"&gt;&lt;a class="main-nav__link " href="kontakt.html"&gt;Kontakt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


My problem is that I don't know how to set custom class for &lt;a href=""&gt; tags. Is there any way how can do it using link() function. In Drupal 7 is l() function but attributes aren't similar. l() has also third attribute with possibility to add options. Is it true, that link($title, $url) accepts only 2 parameters? Because I can't find the way how to send options for link($title, $url). I don't insit on link() function, so if there is some better way please let me know. I'm open to new ideas :)

Thanks
Just incase someone stumbles upon this, Martin's solve above breaks URL fragments as it overrides the URL options completely. The better approach is here:

{{ link(item.title, item.url.setOption('attributes', {'class' : 'main-nav__link'})) }}