04
File-Based Routing Architecture
The directory structure inside app/ defines your application routes automatically.
Supported File Types
- View templates: .ejs, .njk, .nunjucks, .hbs, .liquid, .html
- Page companion files: .ts or .js files sharing the same base name as the view (e.g. index.ts for index.ejs)
- API route files: Any .ts or .js file located under app/api/
- Folder middleware files: middleware.ts or middleware.js
Dynamic Route Syntax, Slugs & Route Groups
- Route Groups (app/(group)/...): Parenthesized folders organize routes and nested layouts without affecting URL pathnames (e.g. app/(auth)/login.ejs -> /login, app/(dashboard)/settings.ejs -> /settings).
| Pattern | Example File Path | Matched Route | Companion Access | View Access |
|---|---|---|---|---|
| Single Parameter | app/products/[id].ejs | /products/:id | req.params.id | R.params.id |
| Catch-All Wildcard Slug | app/docs/[...slug].ejs | /docs/* | req.params.slug | R.params.slug |
| Index Route | app/index.ejs | / | N/A | N/A |
| Route Groups | app/(auth)/login.ejs | /login | N/A | N/A |
Reserved Filenames
| Filename | Role |
|---|---|
| layout.ejs | Nested layout template wrapping page templates in the current folder. |
| middleware.ts / middleware.js | Directory-level middleware (never routed as a standalone page). |
| 404.ejs, 500.ejs, not-found.ejs, error.ejs | Custom HTTP status error fallback templates. |