Functions

useSelectedLayoutSegments

Client hook returns active segments below the surrounding layout. Route groups may appear, and a catch-all may be returned as one joined string rather than one array item per URL component. Use it for segment-aware UI, not unvalidated URL creation. A named parallel slot can be selected explicitly. Source: https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segments. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
useSelectedLayoutSegments(parallelRoutesKey?)

Working Example

Example Snippetnextjs
'use client';import { useSelectedLayoutSegments } from 'next/navigation';export default function SegmentInspector() {  const parts = useSelectedLayoutSegments();  return <pre>{JSON.stringify(parts)}</pre>;}
Next.js Reference