Skip to content

our-active-class

Added in v0.6.0

our-active-class goes on an <a>. When the link points to the page being rendered, or to any page above it, the class in the attribute is added to the link’s class.

@foreach (var item in Model.Root().Children)
{
<a href="@item.Url()" class="nav-link" our-active-class="nav-link--active">@item.Name</a>
}

A navigation item stays active while one of its child or grandchild pages is being rendered. Links to other pages, or to children of the current page, don’t get the class.

Add our-active-href to use it on an element that isn’t a link, such as the <li> around one:

<ul>
@foreach (var item in Model.Root().Children)
{
<li our-active-href="@item.Url()" our-active-class="selected">
<a href="@item.Url()" class="nav-link">@item.Name</a>
</li>
}
</ul>
Attribute What it does
our-active-class The class to add when the link is active.
our-active-href The URL to compare, for elements other than <a>. On an <a>, its href is used.

It works with and without culture domains (for example /en/ and /da/), and ignores case, a trailing slash, the query string and the fragment.