Skip to Content
Senri
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 }) => `${} / ${}`);
postId: string
.();
  • Add routes to what createRouter(prefix) returns, the same way as to app
  • 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/stats

Prefixes in route tables

Typed route tables (defineRoutes()) can have a prefix too (Route tables).

const  = ("/orgs/:orgId")({
    "GET /": ({  }) => `org ${}`,
    "GET /members/:memberId": ({ ,  }) => ({ ,  }),
});

.();

On this page