Routing
keiro supports the following types of routes by default similar to NextJS routing.
Directorysrc
- main.ts
Directoryroutes
Directoryposts
- index.ts
- [post_id].ts
Directoryslug
- […rest].ts
Directorycategories
- [[category_id]].ts
Directorytags
- [[…tags]].ts
This file tree ilustrate all the route types in keiro:
-
src/routes/posts/index.ts: static routes- Matches
/posts
- Matches
-
src/routes/posts/[post_id].ts: dynamic routes- Matches
/posts/1,/posts/abc,/posts/d57cd924-a8fa-4970-bb4f-9a5ba705cc2b
- Matches
-
src/routes/posts/slug/[...rest].ts: catch-all routes- Matches
/posts/slug/a/b/c,/posts/slug/one/two
- Matches
-
src/routes/posts/categories/[[category_id]].ts: optional dynamic route- Matches
/posts/categories,/posts/categories/food
- Matches
-
src/routes/posts/tags/[[...tag]].ts: optional catch-all route- Matches
/posts/tags,/posts/tags/programming/javascript
- Matches
This is using the DefaultFileSystemRouteMapper, you can create your own route mapper
and pass it to the fileSystemRouter middleware.
Special files
keiro also supports middleware and 404 files.
src/routes/middleware.tsCalled before each route is calledsrc/routes/404.tsUsed to send a 404 response when not route is matched