Folders Are Routes, Files Define UI
The App Router
Each folder under app/ is a URL segment. Add a page.tsx and that segment becomes a routable URL.
What you'll learn
- Map folders to URL segments
- Recognize the file-convention pattern (page, layout, loading, error)
- See how nesting composes layouts
The App Router replaces the older Pages Router with a more powerful model: folders are URL segments, and special filenames inside each segment define UI behavior.
Folders Become URLs
app/
page.tsx # /
about/
page.tsx # /about
blog/
page.tsx # /blog
[slug]/
page.tsx # /blog/:slug A folder without a page.tsx is not a route — it can still host shared layout or
loading files for its children, but the URL itself will 404.
The File Conventions
Inside any segment folder you can drop files with special names:
page.tsx— the UI for that routelayout.tsx— wraps the segment and its childrenloading.tsx— Suspense fallback shown while data loadserror.tsx— error boundary for the segmentnot-found.tsx— rendered whennotFound()is calledtemplate.tsx— like layout, but remounts on navigationroute.ts— HTTP API for the segment
Nesting Composes
Layouts compose top-down. A page deep in the tree is wrapped by every layout above it.
// app/dashboard/layout.tsx — wraps /dashboard and its children
export default function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="dashboard">
<aside>Nav</aside>
<section>{children}</section>
</div>
);
} A request to /dashboard/settings renders the root layout, then the dashboard layout,
then app/dashboard/settings/page.tsx inside both.
Quick Mental Model
Think of app/ as the routing tree. Each folder is a node, special filenames are the
node’s behavior, and nesting builds the final UI by composing layouts around the leaf
page. The next lesson zooms in on page.tsx.