Advertisement
Beginner Next.js, Routing (App/Pages Router)

How does file based routing work in the Next.js App Router?

Short answer

In the App Router, every folder inside the app directory represents a segment of the URL path, and adding a file named page.js inside that folder makes it a visitable route, so the folder structure of your project directly mirrors the URL structure of your website.

Save Next.js mock interview
Advertisement
AModel answer
In the App Router, every folder inside the app directory represents a segment of the URL path, and adding a file named page.js inside that folder makes it a visitable route, so the folder structure of your project directly mirrors the URL structure of your website.
// app/about/page.js is accessible at /about
// app/contact/page.js is accessible at /contact
export default function AboutPage() {
  return <h1>About Us</h1>;
}
Real-world example
A company website organizes its about, contact, and pricing pages simply by creating matching folders with page.js files inside the app directory, with no separate routing configuration needed.
Likely follow-ups
  • What file name is required to make a folder into a visitable page?
  • Can a folder exist without a page.js file inside the App Router?
Related topics