DocsChoose
Routing
Nexy has two routers. Pick one per feature; they can coexist in the same application.
Not sure? Use file-based routing. It covers pages and API endpoints with no setup. Add the modular router when a backend needs controllers, injected services or guards.
| You are building | Use |
|---|---|
| Pages, content, a site with a few endpoints | File-based |
| A large API with services shared across routes | Modular |
| Both: pages for people, a structured API for machines | File-based and modular together |
src/routes/index.nexy → /
src/routes/about.nexy → /about
src/routes/blog/index.nexy → /blog
src/routes/blog/[slug].nexy → /blog/:slug
src/routes/(app)/dashboard.nexy → /dashboard
src/routes/api/users.py → /api/users (GET, POST, …)
| Router | Source | Enabled by |
|---|---|---|
| File-based (FBR) | every file under src/routes/ |
the directory exists |
| Modular | controllers and modules | useRouter = AppModule in nexyconfig.py |
FBR is scanned whenever src/routes/ exists, even with a modular router mounted.
File-based routing
A route is a file. The URL is its path under src/routes/, minus the extension. Like Next.js, a
project is in one of two modes, chosen with useCSR:
useCSR = False (default) |
useCSR = True |
|
|---|---|---|
| Pages | .nexy, .md, .mdx |
files of your client framework |
| Root layout | layout.nexy |
layout.tsx (React) |
| Client components | allowed, as islands inside pages | the pages themselves |
| API routes | .py |
.py |
See Server mode and client mode.
| Section | What it covers |
|---|---|
| fbr/pages | pages, dynamic routes and route groups |
| fbr/layouts | layout.nexy, layout.tsx, layout.vue, layout.svelte |
| fbr/handlers | .py route handlers, validation and errors |
| fbr/dependencies | dependencies.py and guards, inherited by directory |
| fbr/middleware | middleware.py, inherited by directory |
| fbr/errors | notfound.nexy, errors.nexy, JSON errors |
| fbr/navigation | linking, client navigation, hooks |
| fbr/realtime | WebSocket handlers |
| fbr/inheritance | how layouts, dependencies and error pages inherit |
Modular routing
Controllers, modules and dependency injection, in the style of NestJS. See Modular routing and Nexy and NestJS.
Next steps
- File-based routing
- Rendering
- Views: what goes inside the files