Functions

useSelectedLayoutSegment

Client hook reads the active segment one level below the layout where the component is mounted. It can be null and may target a named parallel slot. A section can be active on descendant pages; distinguish section styling from exact current page semantics. This example assumes root layout, no basePath and no rewrite. Source: https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segment. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
useSelectedLayoutSegment(parallelRoutesKey?)

Working Example

Example Snippetnextjs
'use client';import Link from 'next/link';import {usePathname,useSelectedLayoutSegment} from 'next/navigation';export default function CatalogLink(){ const active=useSelectedLayoutSegment()==='catalog'; const exact=usePathname()==='/catalog'; return <Link href="/catalog" className={active?'active':undefined} aria-current={exact?'page':undefined}>Catalog</Link>;}
Next.js Reference