Skip to content

Commit ef86d05

Browse files
jamesopstadkorinnekodster28
authored andcommitted
Replace Remix framework guide with new React Router framework guide (#21471)
* Create React Router framework page * Update React Router framework page * Add frameworks-bindings partial * Remove Remix guide * Tweaks * Add links to React Router framework guide from Vite plugin docs * Vite docs tweaks * Add file names to .env file examples * Remove unused components * Add redirect * Update src/content/docs/workers/frameworks/framework-guides/react-router.mdx Co-authored-by: Kody Jackson <[email protected]> * Update src/content/docs/workers/frameworks/framework-guides/react-router.mdx Co-authored-by: Kody Jackson <[email protected]> * Update src/content/docs/workers/frameworks/framework-guides/react-router.mdx Co-authored-by: Kody Jackson <[email protected]> --------- Co-authored-by: korinne <[email protected]> Co-authored-by: Kody Jackson <[email protected]>
1 parent 98ff988 commit ef86d05

File tree

6 files changed

+115
-70
lines changed

6 files changed

+115
-70
lines changed

public/__redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@
15271527
/workers/tutorials/create-sitemap-from-sanity-cms/ /developer-spotlight/tutorials/create-sitemap-from-sanity-cms/ 301
15281528
/workers/tutorials/custom-access-control-for-files-in-r2-using-d1-and-workers/ /developer-spotlight/tutorials/custom-access-control-for-files/ 301
15291529
/workers/tutorials/generate-dynamic-og-images-using-workers/ /workers/tutorials/ 302
1530+
/workers/frameworks/framework-guides/remix/ /workers/frameworks/framework-guides/react-router/ 301
15301531

15311532
# workers ai
15321533
/workers-ai/models/llm/ /workers-ai/models/#text-generation 301
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
pcx_content_type: how-to
3+
title: React Router (formerly Remix)
4+
description: Create a React Router application and deploy it to Cloudflare Workers
5+
---
6+
7+
import {
8+
Render,
9+
PackageManagers,
10+
Steps,
11+
Details,
12+
FileTree,
13+
} from "~/components";
14+
15+
**Start from CLI**: Scaffold a full-stack app with [React Router v7](https://reactrouter.com/) and the [Cloudflare Vite plugin](/workers/vite-plugin/) for lightning-fast development.
16+
17+
<PackageManagers
18+
type="create"
19+
pkg="cloudflare@latest my-react-router-app"
20+
args="--framework=react-router"
21+
/>
22+
23+
**Or just deploy**: Create a full-stack app using React Router v7, with CI/CD and previews all set up for you.
24+
25+
[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/main/react-router-starter-template)
26+
27+
## What is React Router?
28+
29+
[React Router v7](https://reactrouter.com/) is a full-stack React framework for building web applications.
30+
It combines with the [Cloudflare Vite plugin](/workers/vite-plugin/) to provide a first-class experience for developing, building and deploying your apps on Cloudflare.
31+
32+
## Creating a full-stack React Router app
33+
34+
<Steps>
35+
1. **Create a new project with the create-cloudflare CLI (C3)**
36+
37+
<PackageManagers
38+
type="create"
39+
pkg="cloudflare@latest my-react-router-app"
40+
args="--framework=react-router"
41+
/>
42+
<Details header="How is this project set up?">
43+
Below is a simplified file tree of the project.
44+
<FileTree>
45+
- my-react-router-app
46+
- app
47+
- routes
48+
- ...
49+
- entry.server.ts
50+
- root.tsx
51+
- routes.ts
52+
- workers
53+
- app.ts
54+
- react-router.config.ts
55+
- vite.config.ts
56+
- wrangler.jsonc
57+
</FileTree>
58+
59+
`react-router.config.ts` is your [React Router config file](https://reactrouter.com/explanation/special-files#react-routerconfigts).
60+
In this file:
61+
- `ssr` is set to `true`, meaning that your application will use server-side rendering.
62+
- `future.unstable_viteEnvironmentApi` is set to `true` to enable compatibility with the [Cloudflare Vite plugin](/workers/vite-plugin/).
63+
64+
:::note
65+
SPA mode and prerendering are not currently supported when using the [Cloudflare Vite plugin](/workers/vite-plugin/).
66+
If you wish to use React Router in an SPA then we recommend starting with the [React template](/workers/frameworks/framework-guides/react/) and using React Router [as a library](https://reactrouter.com/start/data/installation).
67+
:::
68+
69+
`vite.config.ts` is your [Vite config file](https://vite.dev/config/).
70+
The React Router and Cloudflare plugins are included in the `plugins` array.
71+
The [Cloudflare Vite plugin](/workers/vite-plugin/) runs your server code in the Workers runtime, ensuring your local development environment is as close to production as possible.
72+
73+
`wrangler.jsonc` is your [Worker config file](/workers/wrangler/configuration/).
74+
In this file:
75+
- `main` points to `./workers/app.ts`.
76+
This is the entry file for your Worker.
77+
The default export includes a [`fetch` handler](/workers/runtime-apis/fetch/), which delegates the request to React Router.
78+
- If you want to add [bindings](/workers/runtime-apis/bindings/) to resources on Cloudflare's developer platform, you configure them here.
79+
</Details>
80+
81+
2. **Develop locally**
82+
83+
After creating your project, run the following command in your project directory to start a local development server.
84+
<PackageManagers type="run" args="dev" />
85+
<Details header="What's happening in local development?">
86+
This project uses React Router in combination with the [Cloudflare Vite plugin](/workers/vite-plugin/).
87+
This means that your application runs in the Cloudflare Workers runtime, just like in production, and enables access to local emulations of bindings.
88+
</Details>
89+
90+
3. **Deploy your project**
91+
92+
Your project can be deployed to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/) from your own machine or from any CI/CD system, including Cloudflare's own [Workers Builds](/workers/ci-cd/builds/).
93+
94+
The following command will build and deploy your project. If you are using CI, ensure you update your ["deploy command"](/workers/ci-cd/builds/configuration/#build-settings) configuration appropriately.
95+
96+
<PackageManagers type="run" args={"deploy"} />
97+
98+
</Steps>
99+
100+
## Use bindings with React Router
101+
102+
With bindings, your application can be fully integrated with the Cloudflare Developer Platform, giving you access to compute, storage, AI and more.
103+
As you have direct access to your Worker entry file (`workers/app.ts`), you can also add additional exports such as [Durable Objects](/durable-objects/) and [Workflows](/workflows/).
104+
105+
<Render file="frameworks-bindings" />

src/content/docs/workers/frameworks/framework-guides/remix.mdx

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/content/docs/workers/vite-plugin/get-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PackageManagers, WranglerConfig } from "~/components";
1010

1111
:::note
1212
This guide demonstrates creating a standalone Worker from scratch.
13-
{/* Add link to React Router framework guide */}If you would instead like to create a new application from a ready-to-go template, refer to the [React](/workers/frameworks/framework-guides/react/) or [Vue](/workers/frameworks/framework-guides/vue/) framework guides.
13+
If you would instead like to create a new application from a ready-to-go template, refer to the [React Router](/workers/frameworks/framework-guides/react-router/), [React](/workers/frameworks/framework-guides/react/) or [Vue](/workers/frameworks/framework-guides/vue/) framework guides.
1414
:::
1515

1616
## Start with a basic `package.json`
@@ -81,7 +81,7 @@ export default {
8181
};
8282
```
8383

84-
A request to this Worker will return 'Running in Cloudflare-Workers!', demonstrating that the code is running inside the Workers runtime.
84+
A request to this Worker will return **'Running in Cloudflare-Workers!'**, demonstrating that the code is running inside the Workers runtime.
8585

8686
## Dev, build, preview and deploy
8787

src/content/docs/workers/vite-plugin/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: A full-featured integration between Vite and the Workers runtime
99
The Cloudflare Vite plugin enables a full-featured integration between [Vite](https://vite.dev/) and the [Workers runtime](/workers/runtime-apis/).
1010
Your Worker code runs inside [workerd](https://github.com/cloudflare/workerd), matching the production behavior as closely as possible and providing confidence as you develop and deploy your applications.
1111

12-
### Features
12+
## Features
1313

1414
- Uses the Vite [Environment API](https://vite.dev/guide/api-environment) to integrate Vite with the Workers runtime
1515
- Provides direct access to [Workers runtime APIs](/workers/runtime-apis/) and [bindings](/workers/runtime-apis/bindings/)
@@ -18,16 +18,16 @@ Your Worker code runs inside [workerd](https://github.com/cloudflare/workerd), m
1818
- Leverages Vite's hot module replacement for consistently fast updates
1919
- Supports `vite preview` for previewing your build output in the Workers runtime prior to deployment
2020

21-
### Use cases
21+
## Use cases
2222

23-
- React Router v7 (support for more full-stack frameworks is coming soon)
23+
- [React Router v7](https://reactrouter.com/) (support for more full-stack frameworks is coming soon)
2424
- Static sites, such as single-page applications, with or without an integrated backend API
2525
- Standalone Workers
2626
- Multi-Worker applications
2727

28-
### Get started
28+
## Get started
2929

30-
{/* Add link to React Router framework guide */}To create a new application from a ready-to-go template, refer to the [React](/workers/frameworks/framework-guides/react/) or [Vue](/workers/frameworks/framework-guides/vue/) framework guides.
30+
To create a new application from a ready-to-go template, refer to the [React Router](/workers/frameworks/framework-guides/react-router/), [React](/workers/frameworks/framework-guides/react/) or [Vue](/workers/frameworks/framework-guides/vue/) framework guides.
3131

3232
To create a standalone Worker from scratch, refer to [Get started](/workers/vite-plugin/get-started/).
3333

src/content/docs/workers/vite-plugin/reference/cloudflare-environments.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,11 @@ vars = { MY_VAR = "Production var" }
8787

8888
Next, provide `.env.staging` and `.env.production` files:
8989

90-
```sh
91-
# .env.staging
92-
90+
```sh title=".env.staging"
9391
CLOUDFLARE_ENV=staging
9492
```
9593

96-
```sh
97-
# .env.production
98-
94+
```sh title=".env.production"
9995
CLOUDFLARE_ENV=production
10096
```
10197

0 commit comments

Comments
 (0)