Link

Localized link anchors integrated with the router.

The Link and NavLink primitives extend standard HTML anchor links by integrating language locales, base directories, and SPA route navigation.

Quick StartLink

Create localized, SPA-aware routing links:

tsx
import { Link, NavLink } from 'boltdocs/primitives'

export default function SidebarNav() {
  return (
    <div className="flex flex-col gap-2">
      {/* 1. Standard localized navigation */}
      <Link href="/getting-started" className="text-primary-500 hover:underline">
        Getting Started
      </Link>

      {/* 2. NavLink with automatic active-state highlighting */}
      <NavLink
        href="/api/config-reference"
        className={({ isActive }) =>
          `px-3 py-1 rounded text-sm ${isActive ? 'bg-primary-500 text-white' : 'text-muted hover:bg-soft'}`
        }
      >
        Config Reference
      </NavLink>
    </div>
  )
}

Internal MechanicsLink

  • Localization: Direct href strings (such as /getting-started) are parsed and automatically translated through the useLocalizedTo hook. For example, on a Spanish-localized page, /getting-started is transparently transformed to /es/getting-started.
  • SPA Routing: Clicks on internal links intercept the browser's default navigation to perform fast client-side routing, preventing full page reloads.

Component PropsLink

Inherits all standard HTML anchor (<a>) element attributes:

PropertyTypeDefaultDescription
hrefstringundefinedTarget route path (e.g., /docs/getting-started).
prefetch'hover' | 'none''hover'Preload strategy for router link targets.

Extends the standard Link props:

PropertyTypeDefaultDescription
hrefstringundefinedTarget route path.
endbooleanfalseWhen set to true, the link is only highlighted as active when the routes match exactly.
classNamestring | ((props: { isActive: boolean }) => string)undefinedStyle class name, supporting conditional logic functions.
childrenReactNode | ((props: { isActive: boolean }) => ReactNode)undefinedChild nodes, supporting conditional render functions.

Customization & statesLink

Link is style-neutral — it renders a standard <a> with localized routing, prefetching, and SPA navigation, but no visuals. Its data-* props pass straight through to the anchor. NavLink adds route matching: when the current route matches href, the link is treated as active, and you receive that state through the className / children render functions (a plain active class is appended when you pass a string className).

State / SlotMechanism
NavLink className (function)Receives { isActive } — return the classes for the active / inactive states
NavLink children (function)Receives { isActive } for conditional content
active classAppended to NavLink when the current route matches (when className is a string)
end proptrue matches only the exact path; false (default) matches any path that starts with it
data-* attributesPass through from props to the <a> element
refForwarded to the rendered anchor

Tailwind v4:

tsx
<NavLink
  href="/docs/guides"
  className={({ isActive }) =>
    `px-3 py-1 rounded text-sm ${
      isActive ? 'bg-primary-500/10 text-primary-400' : 'text-muted hover:bg-soft'
    }`
  }
>
  Guides
</NavLink>

Or vanilla CSS:

css
a.active {
  color: var(--color-primary-400);
  background: color-mix(in srgb, var(--color-primary-500) 10%, transparent);
}
Last updated on October 18, 2026

Was this page helpful?