# Breadcrumbs

> Reading an array of all active segments below a layout.

Subject: Next.js | Lesson 43 of 65 | 3 min read
Interactive lesson: https://codewithanimation.in/nextjs/use-selected-layout-segments
Previous: [Layout Segments](https://codewithanimation.in/nextjs/use-selected-layout-segment.md) | Next: [Route Handlers (APIs)](https://codewithanimation.in/nextjs/route-handlers.md)

## The Segment Array

`useSelectedLayoutSegments` is a Client Component hook that returns an array containing all active route segments below the layout where it is called.

## Building Breadcrumbs

While the singular version of this hook is used for styling active tabs, the plural version is almost exclusively used for building breadcrumb navigation components.

By mapping over the returned array, you can dynamically generate links like `Home > Store > Shoes > Nike`.

## Relative Depth

Just like `useSelectedLayoutSegment`, this hook is relative.

If called in the root `/app/layout.tsx` while visiting `/store/shoes`, it returns `['store', 'shoes']`.

If called in `/app/store/layout.tsx` for the exact same URL, it returns `['shoes']`.

## Common mistake: Route Groups

Because Route Groups (like `(auth)`) do not affect the URL, they are omitted from the returned array.

If you need to know about Route Groups for UI logic, you should not rely on this hook.

## Try it: The Breadcrumb Builder

Click the deeply nested routes below to see how the array populates, and how you can map it into a breadcrumb UI.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/use-selected-layout-segments

## Check yourself

### Question 1

You call `useSelectedLayoutSegments()` in `/app/dashboard/layout.tsx`. The user visits `/dashboard/settings/security/keys`. What does the hook return?

- A. `['settings', 'security', 'keys']`
- B. `['dashboard', 'settings', 'security', 'keys']`
- C. `['settings']`
- D. `'settings/security/keys'`

Correct answer: A

The hook returns an array of all segments directly below the layout where it was called. It does not include 'dashboard'.

- Why not B: It does not include the layout it was called from.
- Why not C: That is what the singular `useSelectedLayoutSegment` returns.
- Why not D: It returns an array of strings, not a single string.

## Remember this

- `useSelectedLayoutSegments` returns an array of all active segments below the calling layout.
- It is primarily used for building breadcrumb UI.
- It is relative to where it is called (does not include parent segments).
- It returns an empty array `[]` if there are no child segments.
