File UI routes
Routes live under app/routes. Ness generates the React Router route config and keeps generated wrappers in app/.ness; do not edit that directory.
app/routes/
βββ page.tsx # /
βββ layout.tsx # shared layout
βββ loading.tsx # hydration/pending fallback
βββ error.tsx # error boundary
βββ not-found.tsx # thrown and unmatched 404
βββ forbidden.tsx # thrown 403
βββ unauthorized.tsx # thrown 401
βββ middleware.ts # route middleware
βββ blog/[slug]/page.tsx # /blog/:slug
Segmentsβ
[slug]is dynamic.[...parts]and[[...parts]]are catch-all segments.(marketing)groups files without adding a URL segment._componentsis private and does not add a URL segment.
Server dataβ
A page may keep client-safe exports in page.tsx and server-only work in page.server.ts:
// app/routes/blog/[slug]/page.server.ts
export async function loader({ params }: { params: { slug: string } }) {
return db.post.findUniqueOrThrow({ where: { slug: params.slug } });
}
export async function action({ request }: { request: Request }) {
const form = await request.formData();
await updatePost(form);
return { ok: true };
}
Use <Form> and fetchers for mutations; they progressively enhance native HTML forms and automatically revalidate route data.
NestJS server routesβ
// app/server/posts/posts.controller.ts
import { Body, Controller, Get, Post } from '@nestjs/common';
@Controller('posts')
export class PostsController {
@Get()
findAll() {
return db.post.findMany();
}
@Post()
create(@Body() input: CreatePost) {
return db.post.create({ data: input });
}
}
Controllers are mounted below /api by default, so this controller handles /api/posts. Nest owns controllers, providers, guards, pipes, interceptors, and dependency injection; React Router continues to own pages, layouts, loaders, actions, and SSR.
Generate and register a controller with ness g controller posts. See NestJS backend for modules, configuration, and the production bridge.
Low-level React Router route.ts resource modules remain available as an escape hatch for Web-standard responses, metadata files, and runtime-specific endpoints. Application APIs should use Nest controllers.