Skip to main content

Server-side rendering

To render your app server-side, wrap it with ServerUrlProvider:

import { ServerUrlProvider } from "@swan-io/chicane";
import express from "express";
import { renderToString } from "react-dom/server";
import { App } from "../client/App";

const app = express();

app.use("*", (req, res) => {
const html = renderToString(
<ServerUrlProvider value={req.originalUrl}>
<App />
</ServerUrlProvider>,
);

// …
});