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.

Dynamic routes and route params

Dynamic routes and route params

Now, let's take a situation where we have multiple products in the products route. So for example, if I want to have two products, apple and orange, then certainly there would be two links that take you to the respective product pages. To do so, we would create two folders inside this products folder like this. But imagine you have 50 or 100 or maybe even 1000 products, then there is no way that you create folders for each individual product, right? Not only that, at runtime, new products are added by the users. So anyway, you are not going to include those pages, the product pages I mean, inside your development environment that is coding. So Next.js gives a way to define dynamic routes, which means that we only define one route that will have dynamic value. Let's see how we do it. Ideally to create a route, you create a folder with the route name. In case of dynamic route, we create the folder but the name has to be in square brackets like this and the name can be anything. you will…

Contents