From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

RQ: Catch-all segments in Pages Router

RQ: Catch-all segments in Pages Router

Let's discuss few questions. So what is a catch-all segment in Next.js? A catch-all segment in Next.js is dynamic route that contains one or more path segments. It is used when we need to handle routes that can accept an inconsistent number of segments like products category, subcategory, item. As we have seen in a previous lecture, you can configure the catch all segment route by using the ellipsis that is three dots, and it will match all the subsequent segments in the URL. And if you want to make the catch all segment optional, that is even without writing the dynamic segment, the route should be accessed, then use double square brackets in the naming convention. Second question, can we use catch-all segments with nested routes? The answer is no. Catch-all segments cannot be used with the nested routes in Next.js.

Contents