Routing
File-based routing inspired by Next.js
Routing Guide
Section titled “Routing Guide”NestForge Web uses file-based routing inspired by Next.js.
Route Types
Section titled “Route Types”Pages are React components that render at specific URLs.
| File | Route |
|---|---|
page.tsx | / |
about/page.tsx | /about |
blog/page.tsx | /blog |
blog/[slug]/page.tsx | /blog/:slug |
API Routes
Section titled “API Routes”API routes handle HTTP requests and return JSON.
export async function GET() { return Response.json({ users: [] });}
export async function POST(request: Request) { const body = await request.json(); return Response.json({ created: body });}Layouts
Section titled “Layouts”Layouts wrap pages and persist across route changes.
export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html> <body>{children}</body> </html> );}Dynamic Routes
Section titled “Dynamic Routes”Required Parameters
Section titled “Required Parameters”export default function UserPage({ params }: { params: { id: string } }) { return <h1>User: {params.id}</h1>;}Catch-all Routes
Section titled “Catch-all Routes”// Matches /docs/a, /docs/a/b, /docs/a/b/cexport default function DocPage({ params }: { params: { slug: string[] } }) { return <h1>Docs: {params.slug.join('/')}</h1>;}Optional Catch-all
Section titled “Optional Catch-all”// Matches /, /a, /a/bRoute Groups
Section titled “Route Groups”Prefix directories with parentheses to group routes without affecting the URL:
(app)/ dashboard/ page.tsx → /dashboard settings/ page.tsx → /settingsPrivate Routes
Section titled “Private Routes”Prefix directories with underscore to exclude from routing:
_users/ admin/page.tsx → NOT routed (ignored)Special Files
Section titled “Special Files”| File | Purpose |
|---|---|
layout.tsx | Shared UI for routes |
loading.tsx | Loading state |
error.tsx | Error boundary |
not-found.tsx | 404 page |
route.ts | API endpoints |