@gomani/router
v0.3.0
Published
File-based, constraint-aware routing.
Maintainers
Readme
@gomani/router
File-based, constraint-aware routing for Gomani.
Routing is prescribed — one convention, no assembly decision — and it is a control point for the latency, intermittency, and economic axes: loaders are co-located with routes so critical data ships with the initial HTML (no client waterfall), and route-level code-splitting is automatic.
Conventions (app/routes/)
| File | Route |
| ------------------------ | ------------------------------------ |
| routes/index.tsx | / |
| routes/about.tsx | /about |
| routes/blog/index.tsx | /blog |
| routes/blog/[slug].tsx | /blog/:slug |
| routes/[...rest].tsx | catch-all |
| routes/_layout.tsx | wraps this dir + everything under it |
| routes/_partial.tsx | ignored (underscore = not a route) |
A route module exports a default page and, optionally, a loader (co-located server data) and
staticPaths (params to pre-render for a dynamic route). A _layout.tsx exports a default layout
receiving children.
import { scanRoutes, createRouter } from '@gomani/router';
const router = createRouter(scanRoutes('app/routes'));
const match = router.match('/blog/hello'); // { route, params: { slug: 'hello' } }Matching is specificity-ordered: a static route beats a dynamic sibling, which beats a catch-all.
License
MIT © Venancio Gomani / Kwacha Kulture.
