Breadcrumbs
A parent layout needs to display the current nested path as navigation context.
Next.js 16+ · Hook
A Client Component hook for reading active route segments below the layout where it is called. It returns an array and can optionally inspect a named parallel-route slot.
Call this Client Component hook from a layout to obtain the active route segments beneath that layout. It returns the segments one level down as an array, can target a parallel route slot with an optional key, and returns no items when no child segment is active.
const segments = useSelectedLayoutSegments(parallelRouteKey?: string)| Name | Type | Description |
|---|---|---|
parallelRouteKey | string | undefined | Optional name of the parallel route slot whose active segment should be read. |
An array of strings representing active route segments one level below the calling layout, or an empty array when none exist.
'use client'
import { useSelectedLayoutSegments } from 'next/navigation'
export default function Breadcrumbs() {
const segments = useSelectedLayoutSegments()
return (
<nav aria-label="Breadcrumb">
{segments.map((segment, index) => (
<span key={`${segment}-${index}`}>
{index > 0 && ' / '}{segment}
</span>
))}
</nav>
)
}This Client Component reads the active segments below its layout and renders them as a simple breadcrumb trail.
A parent layout needs to display the current nested path as navigation context.
A layout renders controls whose state depends on which child route is active.
A layout needs to inspect navigation state inside a named slot.
It is a Client Component hook that reads the active route segments below the layout where it runs. The result is an array of strings, or an empty array when no such segments exist.
Follow-up: How would you inspect a named parallel route? Pass its parallel route key as the optional argument, such as useSelectedLayoutSegments('auth').
The hook accepts an optional parallelRouteKey parameter. Supplying it reads the active segment within that parallel-route slot instead of the default route context.
Follow-up: What rendering concern can arise with cacheComponents? The hook may suspend when active segments cannot be resolved during prerendering, so a Suspense boundary may be needed.
It must run in a Client Component, making it suitable for layout-based client UI such as breadcrumbs that depends on active child routes. A layout itself cannot directly access the route segments below it.
Follow-up: When is Suspense unnecessary? Static routes and routes using generateStaticParams can resolve their segments during prerendering, so no boundary is required for this hook.
useSelectedLayoutSegmentusePathnamegenerateStaticParamsSuspenseparallelRouteKey