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.

Catch-all segments in Pages Router

Catch-all segments in Pages Router

Now, let's see the concept of catch all segments and how we deal with them in pages router. Right now, we have the slash products route, which has a child route slash apple, where we have this page. Now, if we add another segment or slug, let's say, for example, I add slash details, then And as you see, we get the 404 error because there is no such route configured. But we can configure the dynamic path such that it will catch all the subsequent path segments, that is, even on adding the slash details, you would be accessing the slash products slash apple route only. Such route segments are called as catch all segments because they catch and are rendered for all the subsequent route segments. To have a catch-all route, we use the three dots like the spread and rest operators, which is actually referred to as ellipses by Next.js in the official documentation. In fact, in computer science, these three dots are generally referred to as ellipses only. So, in the current code, I will put…

Contents