Skip to content
4th April 2025: This is a preview, whilst production-ready, it means some APIs might change

sdk/router

RedwoodSDK’s router is a lightweight server-side router that’s designed to work with defineApp from rwsdk/worker.

route

The route function is used to define a route.

import { route } from "rwsdk/router";
route("/", () => new Response("Hello, World!"));

prefix

The prefix function is used to modify the matched string of a group of routes, by adding a prefix to the matched string. This essentially allows you to group related functionality into a seperate file, import those routes and place it into your defineApp function.

app/pages/user/routes.ts
import { route } from "rwsdk/router";
import { LoginPage } from "./LoginPage";
export const routes = [
route("/login", LoginPage),
route("/logout", () => {
/* handle logout*/
}),
];
worker.ts
import { prefix } from "rwsdk/router";
import { routes as userRoutes } from "@/app/pages/user/routes";
defineApp([prefix("/user", userRoutes)]);

This will match /user/login and /user/logout

render

The render function is used to statically render the contents of a JSX element. It cannot contain any dynamic content. Use this to control the output of your HTML. The rscPayload option is used to toggle the RSC payload that’s appended to the Document. Disabling this will mean that interactivity can no longer work. Your document should not include any client side initialization.

import { render } from "rwsdk/router";
import { ReactDocument } from "@/app/Document";
import { StaticDocument } from "@/app/Document";
import { routes as appRoutes } from "@/app/pages/app/routes";
import { routes as docsRoutes } from "@/app/pages/docs/routes";
export default defineApp([
render(ReactDocument, [prefix("/app", appRoutes)]),
render(StaticDocument, [prefix("/docs", docsRoutes)], { rscPayload: false }),
]);