Skip to content

Routing

File-based routing inspired by Next.js

NestForge Web uses file-based routing inspired by Next.js.

Pages are React components that render at specific URLs.

FileRoute
page.tsx/
about/page.tsx/about
blog/page.tsx/blog
blog/[slug]/page.tsx/blog/:slug

API routes handle HTTP requests and return JSON.

src/app/api/users/route.ts
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 wrap pages and persist across route changes.

src/app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
);
}
src/app/users/[id]/page.tsx
export default function UserPage({ params }: { params: { id: string } }) {
return <h1>User: {params.id}</h1>;
}
src/app/docs/[...slug]/page.tsx
// Matches /docs/a, /docs/a/b, /docs/a/b/c
export default function DocPage({ params }: { params: { slug: string[] } }) {
return <h1>Docs: {params.slug.join('/')}</h1>;
}
src/app/[[...slug]]/page.tsx
// Matches /, /a, /a/b

Prefix directories with parentheses to group routes without affecting the URL:

(app)/
dashboard/
page.tsx → /dashboard
settings/
page.tsx → /settings

Prefix directories with underscore to exclude from routing:

_users/
admin/page.tsx → NOT routed (ignored)
FilePurpose
layout.tsxShared UI for routes
loading.tsxLoading state
error.tsxError boundary
not-found.tsx404 page
route.tsAPI endpoints