Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🔵 App Router – Pages, Layouts & Navigation  ·  Lesson 09

Pages & File-based Routing

The big idea: folders are URLs

In the App Router you never write route tables. Every folder inside app/ is a URL segment, and a folder becomes a visitable page only when it contains a page.jsx file.

app/rootcourses/segmentweb-development/segmentpage.jsxmakes it public/courses/web-developmentfinal URL
Folders + page.jsx = a route

Create your first routes

JSX – three page files
// app/about/page.jsx
export default function AboutPage() {
  return (
    <main className="container">
      <h1>About EduSite</h1>
      <p>We teach coding in Hindi + English since 2018.</p>
    </main>
  )
}

// app/courses/page.jsx
export default function CoursesPage() {
  return <h1>All courses</h1>
}

// app/courses/web-development/page.jsx
export default function WebDevPage() {
  return <h1>Web Development course</h1>
}

Save the files and open /about, /courses and /courses/web-development — no restart needed.

Nested routes

Put folders inside folders to build deeper URLs. app/courses/page.jsx is the index of /courses, and child folders create pages below it.

/app/page.jsx/coursesapp/courses/page.jsx/courses/web-developmentapp/courses/web-development/page.jsx
Each level of folders adds one part to the URL

Folder → URL map

📁 app/
  page.jsx                 # /
  📁 about/
    page.jsx               # /about
  📁 courses/
    page.jsx               # /courses
    📁 web-development/
      page.jsx             # /courses/web-development
  📁 blog/
    page.jsx               # /blog
  📁 contact/
    page.jsx               # /contact
    ContactForm.jsx        # NOT a route (no page.jsx name)
A small site and the URLs it creates

Colocation: keep helpers next to the page

Only page.jsx (and route.js for APIs) is public. You can safely keep components, CSS modules and helpers in the same folder. In EduSite, app/contact/ContactForm.jsx and app/contact/actions.js sit next to the contact page but are not URLs.

💡 Want a folder that is never a route? Start its name with an underscore: app/_utils/. You will meet this again in the Route Groups lesson.

Reading the URL: searchParams

Query strings like ?level=beginner arrive in the page as the searchParams prop. In Next.js 16 it is a Promise, so the page must be async and await it:

JSX – app/courses/page.jsx
// app/courses/page.jsx   →   /courses?level=beginner&sort=fee
export default async function CoursesPage({ searchParams }) {
  const { level = 'all', sort = 'popular' } = await searchParams

  return (
    <main>
      <h1>Courses</h1>
      <p>Showing level: {level} · sorted by: {sort}</p>
    </main>
  )
}
Courses Showing level: beginner · sorted by: fee
💡 Reading searchParams makes the page render on every request (dynamic), because the result depends on the URL.

Pages are Server Components

By default a page runs on the server. It can be async and read files, environment variables or a database directly — that code never reaches the visitor's browser.

JSX – app/blog/page.jsx
// app/blog/page.jsx — a page can be async and read files or a database directly
import { getAllPosts } from '@/lib/posts'

export default async function BlogPage() {
  const posts = getAllPosts()   // runs on the server, never sent to the browser
  return (
    <ul>
      {posts.map((p) => <li key={p.slug}>{p.title}</li>)}
    </ul>
  )
}

Common mistakes

  • app/about.jsx → not a route. Use app/about/page.jsx.
  • Spaces or capitals in folder names (About Us) → ugly URLs like /About%20Us.
  • Reading searchParams.level without await → it is a Promise, so the value is undefined.
  • Two folders producing the same URL (for example via route groups) → build error "two parallel pages".

Summary

  • Folders in app/ become URL segments; page.jsx makes them public.
  • Nest folders for deeper URLs; keep helper files next to pages.
  • searchParams (a Promise) gives you query-string values.
  • Pages are Server Components and can be async.
✅ Practice

Create /courses/python-ai and /courses/android-kotlin pages. On /courses, read ?level= and show "Filter: beginner" when it is present.

Frequently Asked Questions

Do I need to install a router like React Router?
No. Next.js reads the folder structure inside app/ and creates the routes for you.
Can a page file be named index.js?
Not in the App Router. The file must be page.js (or .jsx/.tsx). The folder name gives the URL.
Are URLs case-sensitive?
Yes. Use lowercase folder names with hyphens, like app/about-us/page.js → /about-us. This is also best for SEO.
Why is searchParams awaited?
In Next.js 15 and 16, searchParams and params are Promises. You must await them before reading values.
← Next.js Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicLayouts & Templates Your progress: 9 / 37 (24%) · Lesson 10 / 37 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free