Next.js Course
Next.js
/
Advanced

Catch-All Routes

Definition

An extension of dynamic routes using an ellipsis `[...param]` that captures an array of nested URL segments, rather than just one.

Explain Like I'm New

A standard dynamic route `[id]` only catches ONE slash (e.g. `/shop/shirts`). A catch-all route `[...categories]` catches infinite slashes (e.g. `/shop/mens/shirts/summer/red`). It gathers all those words into an array and hands them to you.

Real World Example

Creating a complex e-commerce filtering system or a documentation site where the URL depth varies wildly (`/docs/react/hooks/useState`).

Common Use Cases

  • •Documentation viewers
  • •Complex nested taxonomies

Interactive Example

Loading Code Playground...

Interview Questions

basic

  • What syntax is used to create a catch-all route folder?

intermediate

  • What is the difference between `[...slug]` and `[[...slug]]` (double brackets)?

Flash Cards

Question

Syntax?

Click to reveal answer
Answer

An ellipsis followed by the variable name in square brackets: `[...slug]`.

Question

Single vs Double brackets?

Click to reveal answer
Answer

`[...slug]` requires at least ONE segment (e.g., `/shop/shirts`). `[[...slug]]` is an OPTIONAL catch-all, meaning it will also match the root route (e.g., just `/shop` with no sub-categories).