C.W.K.
Stream
Lesson 01 of 10 · published

File-Based Routing Basics

~20 min · routing, file system, page.tsx

Level 0Curious
0 XP0/68 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Folders are routes

Inside app/, a folder becomes a route segment when it contains a page.tsx. Nesting folders nests routes:

FileURL
app/page.tsx/
app/about/page.tsx/about
app/blog/page.tsx/blog
app/blog/[slug]/page.tsx/blog/:slug
app/dashboard/settings/page.tsx/dashboard/settings

The "page makes it public" rule

Only page.tsx exposes a route to the world. Other files in the same folder are organizational — they're loaded by the framework but not served as a URL. This means you can park colocated components next to a route without polluting the URL space.

The special file vocabulary

FileRole
page.tsxThe route UI — required to make a segment public.
layout.tsxShared UI wrap. Persists across child navigations.
loading.tsxSuspense fallback for the segment.
error.tsxError boundary (must be a Client Component).
not-found.tsxRendered when notFound() is called inside.
template.tsxLike layout, but re-mounts on every navigation.
default.tsxFallback for parallel route slots on hard navigation.
route.tsAPI endpoint. Can't coexist with page.tsx in the same folder.

Code

A minimal page·tsx
// app/about/page.tsx → /about
export default function AboutPage() {
  return (
    <main className="prose mx-auto p-8">
      <h1>About</h1>
      <p>Server-rendered by default.</p>
    </main>
  );
}
Colocated components don't make routes·text
app/blog/
├── page.tsx               → /blog (public)
├── PostCard.tsx           → not a route, just a sibling
├── useFilters.ts          → not a route
└── [slug]/
    ├── page.tsx           → /blog/:slug (public)
    └── ShareButton.tsx    → not a route

External links

Exercise

Build a five-route site: /, /about, /blog, /blog/[slug], /contact. Add a colocated component to /blog that renders post cards. Confirm that the colocated file does not become a public URL.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.