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

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).

Further reading

Problem with a question

Next.js · Middle · question 51

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz