NavLink

NavLink creates interactive navigation items that connect users to different destinations within an app or external URLs. It automatically indicates active states, supports custom icons and labels, and can execute custom actions instead of navigation when needed.

Key features:

  • Custom actions: Execute JavaScript code instead of navigation when using onClick handlers
  • Visual customization: Support for icons, labels, and completely custom nested content
  • Accessibility support: Proper focus management and keyboard navigation

You can use the label and icon properties of a NavLink to set its text and icon to display. If you want a custom appearance, you can nest define custom visuals for the NavLink by nesting:

<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/">
       <Stack width="16px" height="16px" backgroundColor="purple" />
       Home
    </NavLink>
    <NavLink to="/about">
       <Stack width="16px" height="16px" backgroundColor="green" />
       About
    </NavLink>
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/about">About</Page>
  </Pages>
</App>
Example: NavLink appearance
<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/">
       <Stack width="16px" height="16px" backgroundColor="purple" />
       Home
    </NavLink>
    <NavLink to="/about">
       <Stack width="16px" height="16px" backgroundColor="green" />
       About
    </NavLink>
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/about">About</Page>
  </Pages>
</App>

Actions

By default, activating (clicking) a link navigates to the target URL. However, you can create a link that executes an explicit action responding to the click event instead of the default navigation:

<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/" label="Home" />
    <NavLink label="Danger!" onClick="toast('Be careful with this action!')" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>
Example: custom NavLink action
<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/" label="Home" />
    <NavLink label="Danger!" onClick="toast('Be careful with this action!')" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>

Behaviors

This component supports the following behaviors:

BehaviorProperties
Animationanimation, animationOptions
Bookmarkbookmark, bookmarkLevel, bookmarkTitle, bookmarkOmitFromToc
Publish/SubscribesubscribeToTopic
Tooltiptooltip, tooltipMarkdown, tooltipOptions
Styling Variantvariant

Properties

active

default: false

This property indicates if the particular navigation is an active link. An active link has a particular visual appearance, provided its displayActive property is set to true.

displayActive

default: true

This Boolean property indicates if the active state of a link should have a visual indication. Setting it to false removes the visual indication of an active link.

<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" displayActive="false" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>
Example: displayActive
<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" displayActive="false" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>

enabled

default: true

This boolean property value indicates whether the component responds to user events (true) or not (false).

In the following app, the "Hotels" link is disabled:

<App layout="horizontal">
  <AppHeader>
    <H1>MyTravel App</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" />
    <NavLink label="Flights" to="/flights" />
    <NavLink label="Hotels" to="/hotels" enabled="false" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/flights">Flights Page</Page>
    <Page url="/hotels">Hotels Page</Page>
  </Pages>
</App>
Example: enabled
<App layout="horizontal">
  <AppHeader>
    <H1>MyTravel App</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" />
    <NavLink label="Flights" to="/flights" />
    <NavLink label="Hotels" to="/hotels" enabled="false" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/flights">Flights Page</Page>
    <Page url="/hotels">Hotels Page</Page>
  </Pages>
</App>

exact

When set to true, the link is only considered active when the current URL matches the to value exactly. When false or omitted, the link also counts as active for nested paths that start with the same prefix (e.g. a link with to="/a" is active on "/a/b").

icon

This property allows you to add an optional icon (specify the icon's name) to the navigation link.

<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" icon="home" />
    <NavLink label="Drives" to="/drives" icon="drive" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/drives">Drives Page</Page>
  </Pages>
</App>
Example: icon
<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" icon="home" />
    <NavLink label="Drives" to="/drives" icon="drive" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/drives">Drives Page</Page>
  </Pages>
</App>

iconAlignment

default: "center"

This property controls the vertical alignment of the icon when the label text wraps to multiple lines. Set to baseline to align with the first line of text, start to align to the top, center for middle alignment (default), or end for bottom alignment.

Available values:

ValueDescription
baselineAlign icon with the first line of text
startAlign icon to the top
centerAlign icon to the center (default) (default)
endAlign icon to the bottom

label

This property sets the label of the component. If not set, the component will not display a label.

<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>
Example: label
<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>

level

This property specifies the nesting level (1-4) for the navigation link, which affects its padding. Higher levels typically have more left padding to indicate hierarchy. When used inside a NavGroup, the level is automatically inherited from the group context.

Available values: 1, 2, 3, 4

noIndicator

default: false

This Boolean property controls whether to hide the visual indicator for active and hovered states. When set to true, the indicator line will not be displayed.

target

This optionally property specifies how to open the clicked link.

Available values:

ValueDescription
_selfThe link will open in the same frame as it was clicked.
_blankThe link will open in a new window or tab.
_parentThe link will open in the parent frame. If no parent, behaves as _self.
_topThe topmost browsing context. The link will open in the full body of the window. If no ancestors, behaves as _self.
_unfencedTopAllows embedded fenced frames to navigate the top-level frame, i.e. traversing beyond the root of the fenced frame.

The following example opens the "About XMLUI" link in a new tab:

<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" />
    <NavLink label="About XMLUI" to="https://docs.xmlui.org/" target="_blank" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/drives">Drives Page</Page>
  </Pages>
</App>
Example: target
<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink label="Home" to="/" />
    <NavLink label="About XMLUI" to="https://docs.xmlui.org/" target="_blank" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/drives">Drives Page</Page>
  </Pages>
</App>

to

This property defines the URL of the link.

vertical

This property sets how the active status is displayed on the NavLink component. If set to true, the indicator is displayed on the side which lends itself to a vertically aligned navigation menu. By default, it displays a horizontal indicator.

Usually, you do not need to use this property. However, if you create a custom navigation menu component that runs vertically, you need to manually set this property for the active state to be displayed properly.

The default value for this property is false.

<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" vertical="true" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>
Example: vertical
<App layout="horizontal">
  <NavPanel>
    <NavLink to="/" label="Home" vertical="true" />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
  </Pages>
</App>

Events

click

This event is triggered when the NavLink is clicked.

Signature: click(event: MouseEvent): void

  • event: The mouse event object.

The following example shows a message and navigates to the "/status" link after closing the message window:

<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/" label="Home" />
    <NavLink label="Check my status" onClick="
        toast('You will be redirected');
        Actions.navigate('/status');
    " />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/status">My Status</Page>
  </Pages>
</App>
Example: click
<App layout="horizontal">
  <AppHeader>
    <H1>MyApp</H1>
  </AppHeader>
  <NavPanel>
    <NavLink to="/" label="Home" />
    <NavLink label="Check my status" onClick="
        toast('You will be redirected');
        Actions.navigate('/status');
    " />
  </NavPanel>
  <Pages>
    <Page url="/">Home</Page>
    <Page url="/status">My Status</Page>
  </Pages>
</App>

Exposed Methods

This component does not expose any methods.

Parts

The component has some parts that can be styled through layout properties and theme variables separately:

  • indicator: The active indicator within the NavLink component.

Styling

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-NavLinktransparenttransparent
backgroundColor-NavLink--activenonenone
backgroundColor-NavLink--hovernonenone
backgroundColor-NavLink--hover--activenonenone
backgroundColor-NavLink--pressednonenone
backgroundColor-NavLink--pressed--activenonenone
border-NavLink0px solid $borderColor0px solid $borderColor
borderBottom-NavLinknonenone
borderBottomColor-NavLinknonenone
borderBottomStyle-NavLinknonenone
borderBottomWidth-NavLinknonenone
borderColor-NavLinknonenone
borderEndEndRadius-NavLinknonenone
borderEndStartRadius-NavLinknonenone
borderHorizontal-NavLinknonenone
borderHorizontalColor-NavLinknonenone
borderHorizontalStyle-NavLinknonenone
borderHorizontalWidth-NavLinknonenone
borderLeft-NavLinknonenone
borderLeftColor-NavLinknonenone
borderLeftStyle-NavLinknonenone
borderLeftWidth-NavLinknonenone
borderRadius-indicator-NavLink$borderRadius$borderRadius
borderRadius-NavLink$borderRadius$borderRadius
borderRight-NavLinknonenone
borderRightColor-NavLinknonenone
borderRightStyle-NavLinknonenone
borderRightWidth-NavLinknonenone
borderStartEndRadius-NavLinknonenone
borderStartStartRadius-NavLinknonenone
borderStyle-NavLinknonenone
borderTop-NavLinknonenone
borderTopColor-NavLinknonenone
borderTopStyle-NavLinknonenone
borderTopWidth-NavLinknonenone
borderVertical-NavLinknonenone
borderVerticalColor-NavLinknonenone
borderVerticalStyle-NavLinknonenone
borderVerticalWidth-NavLinknonenone
borderWidth-NavLinknonenone
color-icon-NavLink$color-surface-500$color-surface-500
color-indicator-NavLinknonenone
color-indicator-NavLink--active$color-primary-500$color-primary-500
color-indicator-NavLink--hover$color-primary-600$color-primary-600
color-indicator-NavLink--pressed$color-primary-500$color-primary-500
fontFamily-NavLink$fontFamily$fontFamily
fontSize-NavLinknonenone
fontWeight-NavLink$fontWeight-normal$fontWeight-normal
fontWeight-NavLink--activenonenone
fontWeight-NavLink--pressednonenone
gap-icon-NavLink$space-3$space-3
iconAlignment-NavLinknonenone
lineHeight-NavLink$lineHeight-relaxed$lineHeight-relaxed
outlineColor-NavLink--focus$outlineColor--focus$outlineColor--focus
outlineOffset-NavLink--focus-1px-1px
outlineStyle-NavLink--focus$outlineStyle--focus$outlineStyle--focus
outlineWidth-NavLink--focus$outlineWidth--focus$outlineWidth--focus
padding-level1-NavLinknonenone
padding-level2-NavLinknonenone
padding-level3-NavLinknonenone
padding-level4-NavLinknonenone
padding-NavLinknonenone
paddingBottom-level1-NavLinknonenone
paddingBottom-level2-NavLinknonenone
paddingBottom-level3-NavLinknonenone
paddingBottom-level4-NavLinknonenone
paddingBottom-NavLinknonenone
paddingHorizontal-level1-NavLinknonenone
paddingHorizontal-level2-NavLinknonenone
paddingHorizontal-level3-NavLinknonenone
paddingHorizontal-level4-NavLinknonenone
paddingHorizontal-NavLink$space-4$space-4
paddingLeft-level1-NavLinknonenone
paddingLeft-level2-NavLinknonenone
paddingLeft-level3-NavLinknonenone
paddingLeft-level4-NavLinknonenone
paddingLeft-NavLinknonenone
paddingRight-level1-NavLinknonenone
paddingRight-level2-NavLinknonenone
paddingRight-level3-NavLinknonenone
paddingRight-level4-NavLinknonenone
paddingRight-NavLinknonenone
paddingTop-level1-NavLinknonenone
paddingTop-level2-NavLinknonenone
paddingTop-level3-NavLinknonenone
paddingTop-level4-NavLinknonenone
paddingTop-NavLinknonenone
paddingVertical-level1-NavLinknonenone
paddingVertical-level2-NavLinknonenone
paddingVertical-level3-NavLinknonenone
paddingVertical-level4-NavLinknonenone
paddingVertical-NavLink$space-2$space-2
textColor-NavLink$textColor-primary$textColor-primary
textColor-NavLink--active$color-primary-500$color-primary-500
textColor-NavLink--hovernonenone
textColor-NavLink--hover--activenonenone
textColor-NavLink--pressednonenone
textColor-NavLink--pressed--activenonenone
thickness-indicator-NavLink$space-0_5$space-0_5
wordWrap-NavLinknonenone

Variable Explanations

Theme VariableDescription
color-indicator-NavLinkProvides the following states: --hover, --active, --pressed
iconAlignment-NavLinkSets the default vertical alignment of the icon when the label text wraps to multiple lines. Valid values: baseline, start, center, end
gap-icon-NavLinkSets the gap between the icon and the text label. Only applied when an icon is present.