Skip to main content
Our new developer certification is live!

NavLink

Reusable navigation link component with CSLP support. Handles both internal and external links.

Props

PropTypeRequiredDefaultDescription
buttonNavButtonYes-Navigation button data
indexnumberYes-Index for CSLP key generation
linksCslp{ links?: CSLPFieldMapping }No-CSLP mapping for links
classNamestringNo-CSS classes
onClick() => voidNo-Click handler

Usage

import { NavLink } from '@/components/layout/NavLink';

<NavLink
  button={navButton}
  index={0}
  linksCslp={linksCslp}
  className="hover:text-text-default-strong"
  onClick={() => closeMenu()}
/>

Features

  • Smart routing: Uses Next.js Link for internal routes, <a> for external
  • CSLP support: Applies CSLP attributes to individual links
  • External link handling: Proper target and rel attributes
  • Accessibility: Supports test IDs and click handlers

CSLP

  • CSLP key pattern: links__${index} (e.g., links__0, links__1)
  • CSLP attributes only applied in preview mode
  • Extracted from linksCslp.links[links__${index}]

Behavior

  • Returns null if href is missing or '#'
  • Detects external links by checking if href starts with 'http'
  • Applies target and rel attributes for external links
  • Uses Next.js Link component for internal navigation

Notes

  • Used by DesktopNavigation and MobileNavigation
  • Handles CSLP attribute spreading
  • Supports both server and client-side rendering
  • Automatically handles link type detection