# Catch-all Routes ([...slug])

> Capturing infinitely nested URL segments into an array.

Subject: Next.js | Lesson 15 of 65 | 5 min read
Interactive lesson: https://codewithanimation.in/nextjs/catch-all-routes
Previous: [Dynamic Routes ([slug])](https://codewithanimation.in/nextjs/dynamic-routes.md) | Next: [Optional Catch-all ([[...slug]])](https://codewithanimation.in/nextjs/optional-catch-all.md)

## The spread syntax

Sometimes you need a route to match an unpredictable number of URL segments. For example, a documentation site where a page might be at `/docs/intro` or `/docs/advanced/routing/intercepting`.

You can achieve this by adding the JavaScript spread operator `...` inside the brackets of a dynamic route: `app/docs/[...slug]/page.tsx`.

## Slashes to Arrays

When a user hits a Catch-all route, Next.js splits the URL path by its slashes and passes the result as an Array.

If the route is `/docs/a/b/c`, the extracted parameter will be `slug: ['a', 'b', 'c']`. You can then use this array to traverse your CMS or markdown files to find the correct content.

## Handling the array

In Next.js 15, `params` is a Promise. You must `await` it just like a normal dynamic route.

Once awaited, you often join the array back together: `const path = (await params).slug.join('/');` to query your database.

## Common mistake: The root 404 trap

The most common mistake with `[...slug]` is assuming it matches the root folder.

If you have `app/docs/[...slug]/page.tsx`, and a user visits `/docs/getting-started`, it works. But if they visit just `/docs`, they will get a 404 error. A standard catch-all route requires **at least one** parameter to exist.

## Tip: Combining with static segments

You don't have to put the catch-all at the root. You can safely nest it inside static folders.

For example, `app/shop/categories/[...filters]/page.tsx` is completely valid and will safely capture everything after `/categories/`.

## Try it: Array Extraction

Type a deeply nested URL into the browser bar. Watch how Next.js takes the slashes, splits the string, and injects a JavaScript array into the page component.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/catch-all-routes

## Check yourself

### Question 1

If your folder is app/shop/[...path]/page.tsx, and a user visits /shop/clothes/shirts, what does the awaited params object look like?

- A. { path: 'clothes/shirts' }
- B. { path: ['clothes', 'shirts'] }
- C. { path1: 'clothes', path2: 'shirts' }
- D. ['clothes', 'shirts']

Correct answer: B

A catch-all segment splits the URL slashes and provides an array of strings attached to the parameter name you specified.

- Why not A: Next.js automatically splits the path into an array.
- Why not C: It groups them into a single array under the specified parameter name.
- Why not D: The array is assigned to the key name defined in the brackets (path).

### Question 2

Given app/docs/[...slug]/page.tsx, what happens if a user navigates to exactly /docs?

- A. It returns an empty array: { slug: [] }
- B. It throws a 404 error
- C. It returns undefined: { slug: undefined }
- D. It crashes the server

Correct answer: B

A standard Catch-all route requires at least one parameter segment to match. Without it, `/docs` does not match `[...slug]` and results in a 404.

- Why not A: That behavior belongs to Optional Catch-all routes ([[...slug]]).
- Why not C: The route simply won't match.
- Why not D: It safely returns a 404 Not Found.

## Remember this

- Use `[...name]` to capture an infinite number of nested path segments.
- The extracted value is always an **Array** of strings.
- A standard catch-all route will **404** if there are no segments provided.
- In Next.js 15, you must still `await` the params Promise before accessing the array.
