You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/how-to/route-module.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ export async function loader() {
33
33
}
34
34
```
35
35
36
-
This function is only ever run on the server. On the initial server render, it will provide data to the HTML document. On navigations in the browser, Remix will call the function via [`fetch`][fetch] from the browser.
36
+
This function is only ever run on the server. On the initial server render, it will provide data to the HTML document. On navigations in the browser, React Router will call the function via [`fetch`][fetch] from the browser.
37
37
38
38
This means you can talk directly to your database, use server-only API secrets, etc. Any code that isn't used to render the UI will be removed from the browser bundle.
By default, `clientLoader`**will not** execute for the route during hydration of your Remix app on the initial SSR document request. This is for the primary (and simpler) use-case where the `clientLoader` does not change the shape of the server `loader` data and is just an optimization on subsequent client side navigations (to read from a cache or hit an API directly).
65
+
By default, `clientLoader`**will not** execute for the route during hydration of your React Router app on the initial SSR document request. This is for the primary (and simpler) use-case where the `clientLoader` does not change the shape of the server `loader` data and is just an optimization on subsequent client side navigations (to read from a cache or hit an API directly).
66
66
67
-
If you need to run your `clientLoader` during hydration on the initial document request, you can opt-in by setting `clientLoader.hydrate=true`. This will tell Remix that it needs to run the `clientLoader` on hydration. Without a `HydrateFallback`, your route component will be SSR'd with the server `loader` data - and then `clientLoader` will run and the returned data will be updated in-place in the hydrated route Component.
67
+
If you need to run your `clientLoader` during hydration on the initial document request, you can opt-in by setting `clientLoader.hydrate=true`. This will tell React Router that it needs to run the `clientLoader` on hydration. Without a `HydrateFallback`, your route component will be SSR'd with the server `loader` data - and then `clientLoader` will run and the returned data will be updated in-place in the hydrated route Component.
68
68
69
69
<docs-info>If a route exports a `clientLoader` and does not export a server `loader`, then `clientLoader.hydrate` is automatically treated as `true` since there is no server data to SSR with. Therefore, we always need to run the `clientLoader` on hydration before rendering the route component.</docs-info>
70
70
@@ -153,7 +153,7 @@ See also:
153
153
154
154
## `ErrorBoundary`
155
155
156
-
A Remix`ErrorBoundary` component works just like normal React [error boundaries][error-boundaries], but with a few extra capabilities. When there is an error in your route component, the `ErrorBoundary` will be rendered in its place, nested inside any parent routes. `ErrorBoundary` components also render when there is an error in the `loader` or `action` functions for a route, so all errors for that route may be handled in one spot.
156
+
A React Router`ErrorBoundary` component works just like normal React [error boundaries][error-boundaries], but with a few extra capabilities. When there is an error in your route component, the `ErrorBoundary` will be rendered in its place, nested inside any parent routes. `ErrorBoundary` components also render when there is an error in the `loader` or `action` functions for a route, so all errors for that route may be handled in one spot.
157
157
158
158
The most common use-cases tend to be:
159
159
@@ -169,7 +169,7 @@ To obtain the thrown object, you can use the [`useRouteError`][use-route-error]
169
169
import {
170
170
isRouteErrorResponse,
171
171
useRouteError,
172
-
} from"@remix-run/react";
172
+
} from"react-router";
173
173
174
174
exportfunction ErrorBoundary() {
175
175
const error =useRouteError();
@@ -200,7 +200,7 @@ export function ErrorBoundary() {
200
200
201
201
## `HydrateFallback`
202
202
203
-
A `HydrateFallback` component is your way of informing Remix that you do not want to render your route component until _after_ the `clientLoader` has run on hydration. When exported, Remix will render the fallback during SSR instead of your default route component, and will render your route component client-side once the `clientLoader` completes.
203
+
A `HydrateFallback` component is your way of informing React Router that you do not want to render your route component until _after_ the `clientLoader` has run on hydration. When exported, React Router will render the fallback during SSR instead of your default route component, and will render your route component client-side once the `clientLoader` completes.
204
204
205
205
The most common use-cases for this are client-only routes (such an in-browser canvas game) and augmenting your server data with client-side data (such as saved user preferences).
206
206
@@ -256,7 +256,7 @@ There are a few nuances worth noting around the behavior of `HydrateFallback`:
256
256
- It is only relevant on initial document request and hydration, and will not be rendered on any subsequent client-side navigations
257
257
- It is only relevant when you are also setting [`clientLoader.hydrate=true`][hydrate-true] on a given route
258
258
- It is also relevant if you do have a `clientLoader` without a server `loader`, as this implies `clientLoader.hydrate=true` since there is otherwise no loader data at all to return from `useLoaderData`
259
-
- Even if you do not specify a `HydrateFallback` in this case, Remix will not render your route component and will bubble up to any ancestor `HydrateFallback` component
259
+
- Even if you do not specify a `HydrateFallback` in this case, React Router will not render your route component and will bubble up to any ancestor `HydrateFallback` component
260
260
- This is to ensure that `useLoaderData` remains "happy-path"
261
261
- Without a server `loader`, `useLoaderData` would return `undefined` in any rendered route components
262
262
- You cannot render an `<Outlet/>` in a `HydrateFallback` because children routes can't be guaranteed to operate correctly since their ancestor loader data may not yet be available if they are running `clientLoader` functions on hydration (i.e., use cases such as `useRouteLoaderData()` or `useMatches()`)
@@ -266,16 +266,15 @@ There are a few nuances worth noting around the behavior of `HydrateFallback`:
266
266
Each route can define its own HTTP headers. One of the common headers is the [`Cache-Control` header][cache-control-header] that indicates to browser and CDN caches where and for how long a page is able to be cached.
267
267
268
268
```tsx
269
-
importtype { HeadersFunction } from"@remix-run/node"; // or cloudflare/deno
270
-
271
-
exportconst headers = ({
269
+
exportfunction headers({
272
270
actionHeaders,
273
271
errorHeaders,
274
272
loaderHeaders,
275
273
parentHeaders,
276
-
}) => ({
277
-
"X-Stretchy-Pants": "its for fun",
278
-
"Cache-Control": "max-age=300, s-maxage=3600",
274
+
}) {
275
+
return {
276
+
"X-Stretchy-Pants": "its for fun",
277
+
"Cache-Control": "max-age=300, s-maxage=3600",
279
278
});
280
279
```
281
280
@@ -369,32 +368,32 @@ By default, meta descriptors will render a [`<meta>` tag][meta-element] in most
369
368
- `{ "script:ld+json" }` renders a `<scripttype="application/ld+json">` tag, and its value should be a serializable object that is stringified and injected into the tag.
370
369
371
370
```tsx
372
-
exportconst meta:MetaFunction= () => {
371
+
exportfunction meta() {
373
372
return [
374
373
{
375
374
"script:ld+json": {
376
375
"@context": "https://schema.org",
377
376
"@type": "Organization",
378
-
name: "Remix",
379
-
url: "https://remix.run",
377
+
name: "React Router",
378
+
url: "https://reactrouter.com",
380
379
},
381
380
},
382
381
];
383
-
};
382
+
}
384
383
```
385
384
386
385
A meta descriptor can also render a [`<link>` tag][link-element] by setting the `tagName` property to `"link"`. This is useful for `<link>` tags associated with SEO like `canonical` URLs. For asset links like stylesheets and favicons, you should use the [`links` export][links] instead.
@@ -424,11 +423,11 @@ export function shouldRevalidate({
424
423
}
425
424
```
426
425
427
-
<docs-warning>This feature is an <i>additional</i> optimization. In general, Remix's design already optimizes which loaders need to be called and when. When you use this feature you risk your UI getting out of sync with your server. Use with caution!</docs-warning>
426
+
<docs-warning>This feature is an <i>additional</i> optimization. In general, React Routers's design already optimizes which loaders need to be called and when. When you use this feature you risk your UI getting out of sync with your server. Use with caution!</docs-warning>
428
427
429
-
During client-side transitions, Remix will optimize reloading of routes that are already rendering, like not reloading layout routes that aren't changing. In other cases, like form submissions or search param changes, Remix doesn't know which routes need to be reloaded, so it reloads them all to be safe. This ensures your UI always stays in sync with the state on your server.
428
+
During client-side transitions, React Router will optimize reloading of routes that are already rendering, like not reloading layout routes that aren't changing. In other cases, like form submissions or search param changes, React Router doesn't know which routes need to be reloaded, so it reloads them all to be safe. This ensures your UI always stays in sync with the state on your server.
430
429
431
-
This function lets apps further optimize by returning `false` when Remix is about to reload a route. If you define this function on a route module, Remix will defer to your function on every navigation and every revalidation after an action is called. Again, this makes it possible for your UI to get out of sync with your server if you do it wrong, so be careful.
430
+
This function lets apps further optimize by returning `false` when React Router is about to reload a route. If you define this function on a route module, React Router will defer to your function on every navigation and every revalidation after an action is called. Again, this makes it possible for your UI to get out of sync with your server if you do it wrong, so be careful.
432
431
433
432
`fetcher.load` calls also revalidate, but because they load a specific URL, they don't have to worry about route param or URL search param revalidations. `fetcher.load`'s only revalidate by default after action submissions and explicit revalidation requests via [`useRevalidator`][use-revalidator].
0 commit comments