App Router routes are defined by special file names inside the app/ directory. The folder path becomes the URL; the file name declares the role of that module.
Core files
page.tsx— unique UI for a route segment (required to make a URL public)layout.tsx— shared UI wrapping child segments; can nestloading.tsx— instant fallback UI while segment data loadserror.tsx— error boundary for that segment (must be Client Component)not-found.tsx— UI whennotFound()is calledroute.ts— Route Handler (HTTP API for that segment)template.tsx— like layout but remounts on navigation (rare)
Example tree
app/
layout.tsx
page.tsx
dashboard/
layout.tsx
page.tsx
settings/
page.tsx
loading.tsx
URLs: /, /dashboard, /dashboard/settings. The dashboard layout wraps both dashboard pages.
Private folders
Prefix a folder with _ (e.g. _components) to colocate helpers without creating a route. Route groups use parentheses: (auth) organizes files without changing the URL.
Self-check
- Which file is required for
/contactto exist? - What is the difference between
layout.tsxandtemplate.tsx?