Link
An anchor that knows whether it points at the current page and says so with aria-current.
On this page
Examples
Active state
Matching ignores the query string and the fragment; the active state follows navigation in interactive pages.
Razor
@inject NavigationManager Navigation
@* Links to the current page, to its section (a prefix of the path) and to another page. *@
<nav aria-label="Link states" class="flex flex-wrap items-center gap-4 text-sm">
<KlyLink Href="@_here" Label="This page" data-testid="link-current" />
<KlyLink Href="@_section" Label="Section" data-testid="link-section" />
<KlyLink Href="@_section" Exact Label="Section (exact)" data-testid="link-section-exact" />
<KlyLink Href="/docs" Label="Docs" data-testid="link-other" />
<KlyLink Href="/docs" Label="Disabled" Disabled data-testid="link-disabled" />
</nav>
@code {
private string _here = "/";
private string _section = "/";
protected override void OnInitialized()
{
_here = new Uri(Navigation.Uri).AbsolutePath;
_section = _here[.._here.LastIndexOf('/')];
}
}API
KlyLink
Anchor that marks itself active when its address matches the current page, with an optional disabled state.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Active |
bool? |
Forces the active state instead of comparing Href with the current address. | |
ActiveClass |
string |
Classes added while the link is active, merged after the theme. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Disabled |
bool |
false |
Renders the link without an href , so it cannot be followed or focused. |
Exact |
bool |
false |
Requires the whole path to match to be active. Without it the link is also active on the pages below its path ("/docs" is active on "/docs/theming"), except a link to the root of the app, which is always exact. The query string and the fragment never take part in the comparison. |
Href |
string |
Address the link points to. A link without it is not followable. | |
InactiveClass |
string |
Classes added while the link is not active, merged after the theme. | |
Label |
string |
Text of the link. Use ChildContent for markup. | |
Raw |
bool |
false |
Drops the theme classes, keeping only Class , ActiveClass and InactiveClass . |
Target |
KlyLinkTarget? |
The target attribute, such as Blank . | |
Ui |
LinkUi |
Per-instance class overrides of the slots of the link, see LinkUi . They are merged after the theme and the Class parameter wins on the root slot. |
Slots
| Name | Type | Description |
|---|---|---|
ChildContent |
RenderFragment |
Content of the link. |
Ui slots
Ui takes a LinkUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Base |
Classes merged into the base slot of KlyLink , after the theme and the app configuration. |