Logo

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>

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>

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>

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>

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.
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.

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
color-NavLinknonenone
borderLeftStyle-NavLinknonenone
borderLeftWidth-NavLinknonenone
borderRadius-indicator-NavLink$borderRadius$borderRadius
borderRadius-NavLink$borderRadius$borderRadius
borderRight-NavLinknonenone
color-NavLinknonenone
borderRightStyle-NavLinknonenone
borderRightWidth-NavLinknonenone
borderStartEndRadius-NavLinknonenone
borderStartStartRadius-NavLinknonenone
borderStyle-NavLinknonenone
borderTop-NavLinknonenone
borderTopColor-NavLinknonenone
borderTopStyle-NavLinknonenone
borderTopWidth-NavLinknonenone
borderHorizontal-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-NavLink$fontSize-small$fontSize-small
fontWeight-NavLink$fontWeight-normal$fontWeight-normal
fontWeight-NavLink--activenonenone
fontWeight-NavLink--pressed$fontWeight-normal$fontWeight-normal
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-NavLinknonenone
paddingBottom-NavLinknonenone
paddingHorizontal-NavLink$space-4$space-4
paddingLeft-NavLinknonenone
paddingRight-NavLinknonenone
paddingTop-NavLinknonenone
paddingVertical-NavLink$space-2$space-2
textColor-NavLink$textColor-primary$textColor-primary
textColor-NavLink--activenonenone
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
This site is an XMLUI™ app.