Skip to content

Update documentation to explain behavior in a Catch-all route#89742

Merged
icyJoseph merged 20 commits intovercel:canaryfrom
freek-boon-greenberry:patch-3
Feb 12, 2026
Merged

Update documentation to explain behavior in a Catch-all route#89742
icyJoseph merged 20 commits intovercel:canaryfrom
freek-boon-greenberry:patch-3

Conversation

@freek-boon-greenberry
Copy link
Contributor

No description provided.

Updated useSelectedLayoutSegment docs to explain behavior in a Catch-all route.
Updated useSelectedLayoutSegments to explain behavior in a Catch-all route.
@nextjs-bot nextjs-bot added the Documentation Related to Next.js' official documentation. label Feb 10, 2026
@icyJoseph
Copy link
Member

Thanks for the PR

I do believe this behavior is backed by this e2e:

  • ${'/hooks/use-selected-layout-segment/first/slug2/second/a/b'} | ${['first', 'slug2', '(group)', 'second', 'a/b']} | ${['slug2', '(group)', 'second', 'a/b']}
    ${'/hooks/use-selected-layout-segment/rewritten'} | ${['first', 'slug3', '(group)', 'second', 'catch/all']} | ${['slug3', '(group)', 'second', 'catch/all']}
    ${'/hooks/use-selected-layout-segment/rewritten-middleware'} | ${['first', 'slug3', '(group)', 'second', 'catch/all']} | ${['slug3', '(group)', 'second', 'catch/all']}

Where, pathnames like, /hooks/use-selected-layout-segment/first/slug2/second/a/b, are expected to end up with a a/b entry.

I think the bulletpoints are a good idea, they should stay, but we need to reinforce this gotcha by adding an entry to the Returns tables, like so, adding a small section after the existing tables:

For use-selected-layout-segment.mdx

For catch-all routes (`[...slug]`), the returned segment contains all matched path segments joined as a single string:

| Layout                    | Visited URL       | Returned Segment |
| ------------------------- | ----------------- | ---------------- |
| `app/blog/layout.js`      | `/blog/a/b/c`     | `'a/b/c'`        |

For use-selected-layout-segments.mdx

For catch-all routes (`[...slug]`), all matched path segments are returned as a single joined string within the array:

| Layout                    | Visited URL       | Returned Segments    |
| ------------------------- | ----------------- | -------------------- |
| `app/layout.js`           | `/blog/a/b/c`     | `['blog', 'a/b/c']`  |
| `app/blog/layout.js`      | `/blog/a/b/c`     | `['a/b/c']`          |

…segment.mdx

Co-authored-by: Joseph <sephxd1234@gmail.com>
…segments.mdx

Co-authored-by: Joseph <sephxd1234@gmail.com>
Added example to returns section
Added example to returns section
@freek-boon-greenberry
Copy link
Contributor Author

@icyJoseph I've added your suggestions. Thnx for the input!

…segment.mdx

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
…segments.mdx

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@icyJoseph icyJoseph merged commit 317b7d2 into vercel:canary Feb 12, 2026
62 checks passed
icyJoseph added a commit that referenced this pull request Feb 18, 2026
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Documentation Related to Next.js' official documentation. locked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants