Day 1 — Routing — Folders Become URLs
Foundations & build/Routing — Folders Become URLs
Routing — Folders Become URLs
Your takeaway: Predict a URL from an App Router folder, identify the special page.js file, and know that function names do not create routes.
Routing is the GPS for your website
A visitor requests a URL such as /about. The router matches that path to the page UI your app should show.
In the Next.js App Router, route segments come from folders inside src/app. A special page.js file makes the UI for that route publicly accessible.
1src/app/2├── page.js → /3├── about/4│ └── page.js → /about5└── profile/6 └── page.js → /profileRoute segment
A normal route folder adds part of the path
about folder contributes /about. Nested folders can contribute more segments, such as /about/team.Special file
page.js
page.js default export provides the UI visitors see at that route.Folder-to-route map
Build a route by placing page.js
Choose a page, inspect the folder path, then rename its JavaScript function. The file location controls the URL; the function name does not.
File tree
📁 src
└─ 📁 app
└─ 📄 page.js
- Folder to create
- No extra folder
- Required file path
- src/app/page.js
- Browser URL
- localhost:3000/
export default function Home() {
return (
<h1>Home page</h1>
)
}Use letters, numbers, _ or $. Watch the URL badge—it stays the same.
Home route trap
src/app/page.js creates /. If you create src/app/home/page.js, Next.js creates /home, not the home URL.
The file path controls the URL—not the function name
1// This file is still the / route.2// Renaming the function does not create /about.3export default function About() {4 return <h1>My home page</h1>;5}The component function can be called Page, Home, or About; that name is for people reading the code. Because the file above is src/app/page.js, its URL remains /. A real /about route needs src/app/about/page.js.
Two pieces must match
page.js file. A folder without page.js, or a renamed function inside the home page, does not create the route.How this compares with other approaches
Separate HTML files
Often a new document per page
A basic static site might link to about.html. Servers can also configure cleaner URLs, so the filename is not a universal rule.
React by itself
UI without one required router
React focuses on components. An app can add a routing library or use a framework; React itself does not prescribe one routing setup.
Next.js App Router
An integrated file convention
Organise folders and special files under app; Next.js derives the matching route structure.
Preview: move between routes with <Link>
Creating a page gives us a destination. Next.js also provides the built-in <Link> component for internal navigation. It enables client-side transitions that keep shared UI in place, and Next.js can prefetch eligible routes to make navigation feel fast.
1import Link from "next/link";2 3export default function Navigation() {4 return <Link href="/">Home</Link>;5}Only remember two things for now
Link from next/link, then put the target route in href. In the Components topic, we will unpack why <Link> is a built-in Next.js component and place it alongside <Image /> and shared layout.js UI.Teaching cue: predict firstShow noteHide note
Checkpoint — predict before you click
- What URL comes from
src/app/profile/page.js? - What file supplies the UI for
/? - Does renaming
function Hometofunction Aboutchange the URL?
Answers: /profile, src/app/page.js, and no.
Read later: Next.js — Layouts and Pages