-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Routing System
Nextjs is a fullstack app solution. There are two categories of routing
- Restful API routing
- Page routing
Next.js App Directory File Naming Patterns
Essential file naming conventions in Next.js 14+ app directory.
checklist
| File | Description |
|---|---|
page.tsx |
Default React Server Component for route segments. Defines unique UI and data fetching. Automatically accessible at route's URL. |
layout.tsx |
Shared UI wrapper for route segments. Persists across route changes. Receives children prop for nested components. |
loading.tsx |
Instant loading state using React Suspense. Automatically wraps route segments. Shows while page components are streaming. |
error.tsx |
React Error Boundary wrapper. Catches runtime errors in nested routes. Isolates errors to affected segments. |
not-found.tsx |
Custom 404 error handling. Invoked by notFound() function. Handles non-existent routes and intentional not-found states. |
route.tsx |
Route Handlers for API functionality. Supports HTTP methods (GET, POST, etc.). Direct access to Next.js's Edge Runtime. |
middleware.ts |
Global route and request interception. JWT validation, authentication, and rewriting. Executes before matching routes. |
route.ts |
API Route Handler defining endpoints with HTTP methods (GET, POST, etc.). Creates API routes at the segment's URL path. Must be placed in app directory. |
default.tsx |
app/@modal/default.tsx , Fallback UI when parallel route isn't active |
template.tsx |
app/blog/template.tsx, New instance per navigation, useful for animations |
Deep dive in.
- template, page and layout
app/
├─ layout.tsx (root)
└─ products/
├─ layout.tsx
├─ template.tsx
├─ page.tsx
└─ [id]/
└─ page.tsx
So these UI layers wrapped like onion, root layout waps the products page layout, the products page layout wraps the template, then template wraps the further page.tsx.
The final effect is like an onion
- Folder structure

Metadata
Metadata
Assignees
Labels
No labels