Menu

File-Based Routing and Pages

Lesson 1: File-Based Routing and Pages

What is file-based routing?

In the App Router, each folder inside app/ is a URL segment, and a page.tsx file inside it makes that segment publicly accessible.

File path

URL

app/page.tsx/
app/about/page.tsx/about
app/courses/page.tsx/courses
app/courses/web/page.tsx/courses/web
app/courses/components/Card.tsxNo route (not a page file)

A folder without page.tsx is part of the path but does not render anything by itself.

Example

// app/about/page.tsx
export default function AboutPage() {
return (
<main>
<h1>About LearnHub</h1>
<p>Beginner-friendly courses in data, design, and development.</p>
</main>
);
}

Visit http://localhost:3000/about and the page appears. No route configuration is needed.

How it works

  1. Next.js scans the app folder at build and dev time.
  2. Each page.tsx becomes a route. Its default export is the component rendered for that URL.
  3. The component is a Server Component by default, so it can be async and fetch data directly (Module 5).
  4. Pages are wrapped by every layout.tsx above them in the folder tree (Lesson 2).

Page props: every page receives two optional props, both of which are Promises in Next.js 15 and later:

Prop

Contains

Example URL

Value after await

paramsDynamic segment values/courses/sql{ slug: 'sql' }
searchParamsQuery string values/search?q=python{ q: 'python' }

Common mistakes

Mistake

Effect

Fix

Named export instead of defaultRoute shows an errorUse export default function Page()
Creating app/about.tsxNo route is createdUse a folder: app/about/page.tsx
Both page.tsx and route.ts in one folderBuild error: conflictKeep API endpoints in a separate folder such as app/api/
Reading searchParams.q without awaitUndefined value or type errorconst { q } = await searchParams

Key takeaways

  • Folder = URL segment. page.tsx = the public page for that segment.
  • Other files can live next to routes safely; only special file names create routes.

Try it: Create /courses, /about, and /contact pages for LearnHub, each with a heading and one paragraph.


Nextjs Tutorial

J

Jebasta





Get in Touch For Details