Mark the active child tab
Parent layout navigation
Next.js 16+ · Hook
A Client Component hook that reads the active route segment one level below the layout where it is called. Use it for route-aware navigation and optionally target a named parallel-route slot.
This Client Component hook reads the active route segment immediately below the layout where it runs. It can inspect a named parallel-route slot, returns the segment as a string or null when absent, and combines catch-all matches into one string.
const segment = useSelectedLayoutSegment(parallelRouteKey?: string)| Name | Type | Description |
|---|---|---|
parallelRouteKey | string | Optional name of the parallel-route slot whose active segment should be read. |
A string containing the active segment, or null if no active segment exists. For catch-all routes, matched segments are returned as one joined string.
'use client'
import { useSelectedLayoutSegment } from 'next/navigation'
export default function NavTabs() {
const segment = useSelectedLayoutSegment()
return (
<nav aria-label="Sections">
{['overview', 'settings'].map((slug) => (
<a
key={slug}
href={`/${slug}`}
aria-current={segment === slug ? 'page' : undefined}
>
{slug}
</a>
))}
</nav>
)
}A Client Component reads the child segment below its layout and marks the matching navigation item as current.
Parent layout navigation
Parallel Routes
Catch-all routing
It is a Client Component hook that reads the active route segment one level below the layout that calls it. The result is a string, or null when no child segment exists.
Follow-up: How would you read all descendants instead? Use useSelectedLayoutSegments, which returns an array of active segments below the calling layout.
The optional parameter is parallelRouteKey. Supplying it selects the active segment from a particular parallel-route slot rather than the default route.
Follow-up: When would this matter? A layout rendering a named slot such as auth can pass 'auth' to inspect that slot's active child.
For a catch-all route such as [...slug], the returned value contains all matched path segments joined into one string. It therefore is not an array of individual segments.
Follow-up: What API should be used for a hierarchy of separate active segments? useSelectedLayoutSegments is the related hook designed to return an array.
useSelectedLayoutSegmentsusePathnameuseParams