Docs
Guide
Routing

Routing

Dobs automatically generates routes based on the file tree of pages. All route files must be located inside the /app/ directory, and every file within this directory is treated as a route. Both .ts and .js extensions are supported.

#Static Routes

Static routes map directly to a specific URL path.

FilenamePath
/index.ts/
/foo.ts/foo
/foo/bar.ts/foo/bar

Example File Tree for Static Routes:

/app
├── index.ts       // → /
├── foo.ts         // → /foo
└── foo
    └── bar.ts     // → /foo/bar

#Dynamic Routes

Dynamic routes use square brackets [ ] to indicate path parameters.

FilenamePath
/[id].ts/:id
/[id]/index.ts/:id
/[id]/foo.ts/:id/foo
/[...params].ts/*params

Example File Tree for Dynamic Routes:

/app
├── [id].ts             // → /:id
├── [id]
│   ├── index.ts        // → /:id
│   └── foo.ts          // → /:id/foo
└── [...params].ts      // → /*params

#Notes

  1. Dynamic Segments: [segment] captures a single path segment. Example: /123, /abc

  2. Nested Dynamic Routes: /[id]/index.ts maps to the same route as /[id]. Nested dynamic routes allow for organizing files under a dynamic folder.

  3. Catch-All Routes: [...params].ts captures multiple path segments as an array. Example: /a/b/c, /x/y


#Example

/app
├── index.ts          → /
├── foo.ts            → /foo
├── foo
│   └── bar.ts        → /foo/bar
├── [id].ts           → /:id
├── [id]
│   ├── index.ts      → /:id
│   └── foo.ts        → /:id/foo
└── [...params].ts    → /*params

This structure provides a clear overview of both static and dynamic routes in Dobs.