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.

Routing with Pages Router

Routing with Pages Router

So, now let's start with how routes configured works in the pages router. To start with, the routing in the app router was done with file system, that is, we created folders to create routes. Now if we consider pages router, then it does support file based routing, but there is some difference in the approach. Let's say I want to create a route slash home slash products. Then in app router, my project structure would be like this, where I have the home folder inside the app directory, and the products folder inside the home. And then the page.js file where we have the code. And in the pages router, you would create the home folder and have a file named products.js. This is much like creating a component. So the slug can be defined as a component. You may choose to have products folder and an index.js inside it, but not the pages.js that we used to have in the app router. Let's try this practically. I will create a route named products first. So as discussed, we can simply create a…

Contents