Routing
Groups
Group routes under a prefix, or mount another app
import { , } from "@senrijs/senri";
const = ();
const = ("/users/:id/posts");
.("/", ({ }) => `posts of user ${}`);
.("/:postId", ({ , postId }) => `${} / ${}`);
.();- Add routes to what
createRouter(prefix)returns, the same way as toapp - Parameters in the prefix (
:id) are typed in the handlers too - Mount it on the app with
app.route(router)
Mount another app
Mount another app made with createApp() under a prefix.
const = ();
.("/stats", () => ({ : 42 }));
.("/admin", ); // GET /admin/statsPrefixes in route tables
Typed route tables (defineRoutes()) can have a prefix too (Route tables).
const = ("/orgs/:orgId")({
"GET /": ({ }) => `org ${}`,
"GET /members/:memberId": ({ , }) => ({ , }),
});
.();