Next.js · Middle · Question 51 of 75
How can a layout highlight the active tab among its child segments?
'use client'
const segment = useSelectedLayoutSegment() // 'settings' on /dashboard/settings- ✓Correct answer: Use
useSelectedLayoutSegment()in a client component rendered by the layout - 2Read the
paramsprop of the layout - it contains child segments - 3Layouts can't know which child page is active
Explanation
Layouts don't re-render on navigation and don't get the child's path. The hook returns the active segment one level below the layout (useSelectedLayoutSegments returns all of them).