Skip to content

Commit bad24c1

Browse files
Merge pull request #11586 from remix-run/brooks/v7-start-doc-updates
docs: small updates to v7 start doc
2 parents 10a6fd0 + aed4ad0 commit bad24c1

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

docs/start/data-loading.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ order: 5
55

66
# Data Loading
77

8-
Data is provided to routes from `loader` and `clientLoader`, accessed in the `data` prop of the Route Component.
8+
Data is provided to the route via `loader` and `clientLoader`, and accessed in the `data` prop of the Route Component.
99

1010
## Client Data Loading
1111

12-
`clientLoader` is used to fetch data on the client. This is useful for projects that aren't server rendering, and for pages you'd prefer to fetch in the browser.
12+
`clientLoader` is used to fetch data on the client. This is useful for projects that aren't server rendering, and for pages you'd prefer fetch their data in the browser.
1313

1414
```tsx filename=app/product.tsx
1515
// route("products/:pid", "./product.tsx");
@@ -37,11 +37,10 @@ export default defineRoute$({
3737

3838
## Server Data Loading
3939

40-
When server rendering, the `loader` export is used to fetch data on the server for both initial page loads and client navigations through an automatic `fetch` by React Router in the browser.
40+
When server rendering, the `loader` method is used to fetch data on the server for both initial page loads and client navigations through an automatic `fetch` by React Router in the browser.
4141

4242
```tsx filename=app/product.tsx
4343
// route("products/:pid", "./product.tsx");
44-
4544
import { defineRoute$ } from "react-router";
4645
import { fakeDb } from "../db";
4746

@@ -71,11 +70,14 @@ Note that the `loader` function is removed from client bundles so you can use se
7170
RSC is supported by returning components from loaders and actions.
7271

7372
```tsx filename=app/product.tsx
73+
// route("products/:pid", "./product.tsx");
7474
import { defineRoute$ } from "react-router";
7575
import Product from "./product";
7676
import Reviews from "./reviews";
7777

7878
export default defineRoute$({
79+
params: ["pid"],
80+
7981
async loader({ params }) {
8082
return {
8183
product: <Product id={params.pid} />,
@@ -96,13 +98,15 @@ export default defineRoute$({
9698

9799
## Static Data Loading
98100

99-
When pre-rendering, the `loader` export is used to fetch data at build time.
101+
When pre-rendering, the `loader` method is used to fetch data at build time.
100102

101103
```tsx filename=app/product.tsx
102104
// route("products/:pid", "./product.tsx");
103105
import { defineRoute$ } from "react-router";
104106

105107
export default defineRoute$({
108+
params: ["pid"],
109+
106110
async loader({ params }) {
107111
let product = await getProductFromCSVFile(params.pid);
108112
return { product };
@@ -147,7 +151,6 @@ Note that when server rendering, any URLs that aren't pre-rendered will be serve
147151

148152
```tsx filename=app/product.tsx
149153
// route("products/:pid", "./product.tsx");
150-
151154
import { defineRoute$ } from "react-router";
152155
import { fakeDb } from "../db";
153156

docs/start/deploying.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ new: true
88

99
React Router can be deployed two ways:
1010

11-
- Static Hosting
1211
- Fullstack Hosting
12+
- Static Hosting
1313

1414
To get the most benefits from React and React Router, we recommend fullstack hosting.
1515

@@ -96,8 +96,6 @@ This template includes:
9696
- Optimized Image Transforms with `<Image/>` and Vercel images
9797
- ISR for statically pre-rendered routes
9898

99-
</div>
100-
10199
[View it live →](#TODO)
102100

103101
### Manual Fullstack Deployment
@@ -120,7 +118,7 @@ You can get started with the following Deploy Now buttons:
120118

121119
### Manual Static Hosting
122120

123-
Ensure the `ssr` flag is not `true` in your Vite config:
121+
Ensure the `ssr` flag is `false` in your Vite config:
124122

125123
```ts
126124
import react from "@react-router/dev/vite";

docs/start/rendering.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are three rendering strategies in React Router:
1313

1414
All routes are always client side rendered as the user navigates around the app. However, you can control server rendering and static pre-rendering with the `ssr` and `prerender` options in the Vite plugin.
1515

16-
## Server Rendering
16+
## Server Side Rendering
1717

1818
```ts filename=vite.config.ts
1919
import { plugin as app } from "@react-router/vite";
@@ -28,7 +28,7 @@ export default defineConfig({
2828
});
2929
```
3030

31-
Server rendering requires a deployment that supports it. Though it's a global setting, individual routes can still be statically pre-rendered, and/or use client data loading with `clientLoader` to avoid server rendering/fetching of their portion of the UI.
31+
Server side rendering requires a deployment that supports it. Though it's a global setting, individual routes can still be statically pre-rendered, and/or use client data loading with `clientLoader` to avoid server rendering/fetching of their portion of the UI.
3232

3333
## Static Pre-rendering
3434

@@ -47,17 +47,28 @@ export default defineConfig({
4747
});
4848
```
4949

50-
Pre-rendering is a build-time operation that generates static HTML and client navigation data payloads for a list of URLs. This is useful for SEO and performance especially for deployments without server rendering.
50+
Pre-rendering is a build-time operation that generates static HTML and client navigation data payloads for a list of URLs. This is useful for SEO and performance, especially for deployments without server rendering. When pre-rendering, the `loader` method is used to fetch data at build time.
5151

5252
## React Server Components
5353

5454
You can return elements from loaders and actions to keep them out of browser bundles.
5555

5656
```tsx
57-
export async function loader() {
58-
return {
59-
products: <Products />,
60-
reviews: <Reviews />,
61-
};
62-
}
57+
export default defineRoute$({
58+
async loader() {
59+
return {
60+
products: <Products />,
61+
reviews: <Reviews />,
62+
};
63+
},
64+
65+
Component({ data }) {
66+
return (
67+
<div>
68+
{data.products}
69+
{data.reviews}
70+
</div>
71+
);
72+
},
73+
});
6374
```

docs/start/routing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ route("dashboard", "./dashboard.tsx", () => [
8383
```
8484

8585
```tsx filename=app/dashboard.tsx
86-
import { createRoute, Outlet } from "react-router";
86+
import { defineRoute$, Outlet } from "react-router";
8787

88-
export default createRoute({
88+
export default defineRoute$({
8989
component: function Dashboard() {
9090
return (
9191
<div>
@@ -151,9 +151,9 @@ route("teams/:teamId", "./team.tsx");
151151
```
152152

153153
```tsx filename=app/team.tsx
154-
import { createRoute } from "react-router";
154+
import { defineRoute$ } from "react-router";
155155

156-
export default createRoute({
156+
export default defineRoute$({
157157
// ensures this route is configured correctly in routes.ts
158158
// and provides type hints for the rest of this route
159159
params: ["teamId"],
@@ -179,7 +179,7 @@ route("c/:categoryId/p/:productId", "./product.tsx");
179179
```
180180

181181
```tsx filename=app/product.tsx
182-
export default createRoute({
182+
export default defineRoute$({
183183
params: ["categoryId", "productId"],
184184

185185
async loader({ params }) {

0 commit comments

Comments
 (0)