Ancor is not added correctly

Ancor is added after # to the main page (site.com/#ancor) – the site domain. But it needs to be added to the current page (site.com/category/article#ancor)

Apparently there is an error here

 generateNavEl: function(anchor, text) {
        var $a = $('<a class="nav-link"></a>');
        $a.attr("href", "#" + anchor);
        $a.text(text);
        var $li = $("<li></li>");
        $li.append($a);
        return $li;
      },

Код взят отсюда