The best way to control Claude Code, Codex and more from any computer or phone
| 1 | --- |
| 2 | title: React Router |
| 3 | description: Deploy React Router v8 framework apps to Prisma Compute with Prisma.Website.ReactRouter — SSR on Bun and native Vite dev locally. |
| 4 | sidebar: |
| 5 | order: 7 |
| 6 | --- |
| 7 | |
| 8 | import PackageManagers from "../../../../components/PackageManagers.astro"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft"; |
| 11 | |
| 12 | `Prisma.Website.ReactRouter` builds [React Router](https://reactrouter.com) |
| 13 | v8 in framework mode through your project's Vite pipeline. The shared |
| 14 | Node target wraps the server manifest with `createRequestHandler` and |
| 15 | serves client assets first. The output runs on **Bun in Prisma Compute** |
| 16 | from a `tar.gz` upload, without a Docker image or registry. |
| 17 | |
| 18 | ## Install |
| 19 | |
| 20 | Install the build-time integration; the resource loads `/react-router` |
| 21 | and `/react-router/node` from your project: |
| 22 | |
| 23 | <PackageManagers dev={devDeps} /> |
| 24 | |
| 25 | Keep the framework scaffold's `react-router`, `@react-router/dev`, |
| 26 | `@react-router/node`, `isbot`, and `vite`. Put `@react-router/node` and |
| 27 | `isbot` in `dependencies`: React Router reads them when choosing its |
| 28 | default server entry and may try to install `isbot` if it is missing. |
| 29 | |
| 30 | ## Configure Vite |
| 31 | |
| 32 | Keep the ordinary framework plugin and your Vite plugins: |
| 33 | |
| 34 | ```typescript |
| 35 | // vite.config.ts |
| 36 | import { reactRouter } from "@react-router/dev/vite"; |
| 37 | import tailwindcss from "@tailwindcss/vite"; |
| 38 | import { defineConfig } from "vite"; |
| 39 | |
| 40 | export default defineConfig({ |
| 41 | plugins: [tailwindcss(), reactRouter()], |
| 42 | }); |
| 43 | ``` |
| 44 | |
| 45 | No deployment adapter or server preset is needed. |
| 46 | |
| 47 | :::caution[Remove the Cloudflare Vite plugin] |
| 48 | A Cloudflare scaffold targets workerd, not the Node-compatible output |
| 49 | used by Prisma. Remove `@cloudflare/vite-plugin` from the config: |
| 50 | |
| 51 | ```diff lang="typescript" |
| 52 | -import { cloudflare } from "@cloudflare/vite-plugin"; |
| 53 | import { reactRouter } from "@react-router/dev/vite"; |
| 54 | import { defineConfig } from "vite"; |
| 55 | |
| 56 | export default defineConfig({ |
| 57 | - plugins: [cloudflare({ viteEnvironment: { name: "ssr" } }), reactRouter()], |
| 58 | + plugins: [reactRouter()], |
| 59 | }); |
| 60 | ``` |
| 61 | |
| 62 | ::: |
| 63 | |
| 64 | ## Declare the Website |
| 65 | |
| 66 | ```typescript |
| 67 | // alchemy.run.ts |
| 68 | import * as Prisma from "@alchemy.run/prisma"; |
| 69 | |
| 70 | export const Website = Prisma.Website.ReactRouter("Website", { |
| 71 | rootDir: "./web", |
| 72 | }); |
| 73 | ``` |
| 74 | |
| 75 | `rootDir` holds `package.json`, `vite.config.*`, and |
| 76 | `react-router.config.ts`; omit it for `.`. Live deploy creates a |
| 77 | database-less project unless you pass `project`. |
| 78 | |
| 79 | ## Add it to the Stack |
| 80 | |
| 81 | ```typescript |
| 82 | // alchemy.run.ts |
| 83 | import * as Alchemy from "alchemy"; |
| 84 | import * as Effect from "effect/Effect"; |
| 85 | |
| 86 | export default Alchemy.Stack( |
| 87 | "MyReactRouterSite", |
| 88 | { providers: Prisma.providers(), state: Alchemy.localState() }, |
| 89 | Effect.gen(function* () { |
| 90 | const site = yield* Website; |
| 91 | return { url: site.url }; |
| 92 | }), |
| 93 | ); |
| 94 | ``` |
| 95 | |
| 96 | `site.url` is the Compute endpoint on deploy. Requests that miss client |
| 97 | assets go to SSR routes, loaders, actions, and resource routes on Bun. |
| 98 | |
| 99 | ## How the two build outputs are deployed |
| 100 | |
| 101 | Both `build/client` and `build/server` go into the uploaded artifact. |
| 102 | The client directory contains browser bundles and `public/` files. |
| 103 | `build/server/index.js` is a manifest, so Alchemy wraps it with React |
| 104 | Router's request handler rather than executing it as a standalone server. |
| 105 | |
| 106 | A custom `buildDirectory` is read from the resolved config. If you set |
| 107 | Vite's `base`, give React Router's `basename` the same prefix so emitted |
| 108 | asset paths match the deployed files. |
| 109 | |
| 110 | ## Add environment variables |
| 111 | |
| 112 | ```diff lang="typescript" |
| 113 | export const Website = Prisma.Website.ReactRouter("Website", { |
| 114 | rootDir: "./web", |
| 115 | + env: { API_BASE: "https://api.example.com" }, |
| 116 | }); |
| 117 | ``` |
| 118 | |
| 119 | Values are applied before build and dev and passed to Compute. `VITE_*` |
| 120 | keys are inlined into browser code; keep secrets out of those keys. |
| 121 | Outputs from sibling resources can be passed in `env` when declaring |
| 122 | the Website inside your Stack generator. |
| 123 | |
| 124 | ## Read the environment in a loader |
| 125 | |
| 126 | ```typescript |
| 127 | // app/routes/home.tsx |
| 128 | export function loader() { |
| 129 | return { apiBase: process.env.API_BASE ?? "unset" }; |
| 130 | } |
| 131 | ``` |
| 132 | |
| 133 | Loaders and actions run on Bun and read `process.env`. |
| 134 | |
| 135 | ## Read the environment in a resource route |
| 136 | |
| 137 | ```typescript |
| 138 | // app/routes/api.hello.ts |
| 139 | export function loader() { |
| 140 | return new Response(process.env.API_BASE ?? "unset"); |
| 141 | } |
| 142 | ``` |
| 143 | |
| 144 | A route module without a default component is a resource route. It |
| 145 | uses the same runtime environment. |
| 146 | |
| 147 | ## Local dev |
| 148 | |
| 149 | `bun alchemy dev` runs React Router's Vite dev server with HMR; the |
| 150 | Website creates no Prisma resources. Opt into live deployment during dev: |
| 151 | |
| 152 | ```typescript |
| 153 | export const Website = Prisma.Website.ReactRouter("Website").pipe( |
| 154 | Alchemy.remote(), |
| 155 | ); |
| 156 | ``` |
| 157 | |
| 158 | ## Custom domain |
| 159 | |
| 160 | ```typescript |
| 161 | const site = yield* Prisma.Website.ReactRouter("Web", { |
| 162 | domain: "app.example.com", |
| 163 | }); |
| 164 | ``` |
| 165 | |
| 166 | `Prisma.CustomDomain` requires the app to be on the current default |
| 167 | branch. Configure returned DNS records yourself and verify status before |
| 168 | cutover; see [Custom domains](/prisma/frontend/websites#custom-domains). |
| 169 | |
| 170 | ## Where next |
| 171 | |
| 172 | - [React Router API](/providers/prisma/website/reactrouter). |
| 173 | - [React Router example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-react-router). |
| 174 | - [Websites](/prisma/frontend/websites) and [Compute apps](/prisma/compute/apps). |