Skip to content

Commit 5bddcce

Browse files
committed
Add cross-links to route modules docs page
1 parent 6352d2e commit 5bddcce

File tree

2 files changed

+64
-44
lines changed

2 files changed

+64
-44
lines changed

docs/start/framework/route-module.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Route modules are the foundation of React Router's framework features, they defi
2323

2424
This guide is a quick overview of every route module feature. The rest of the getting started guides will cover these features in more detail.
2525

26+
For additional details, please refer to the API documentation for a [Route Module][route-module]
27+
2628
## Component (`default`)
2729

2830
Defines the component that will render when the route matches.
@@ -40,6 +42,10 @@ export default function MyRouteComponent() {
4042
}
4143
```
4244

45+
See also:
46+
47+
- [`default` export Component props][component-props]
48+
4349
## `loader`
4450

4551
Route loaders provide data to route components before they are rendered. They are only called on the server when server rendering or during the build with pre-rendering.
@@ -130,6 +136,10 @@ export async function action({ request }) {
130136
}
131137
```
132138

139+
See also:
140+
141+
- [`action` params][action-params]
142+
133143
## `clientAction`
134144

135145
Like route actions but only called in the browser.
@@ -157,9 +167,7 @@ import {
157167
useRouteError,
158168
} from "react-router";
159169

160-
export function ErrorBoundary() {
161-
const error = useRouteError();
162-
170+
export function ErrorBoundary({ error }) {
163171
if (isRouteErrorResponse(error)) {
164172
return (
165173
<div>
@@ -184,6 +192,12 @@ export function ErrorBoundary() {
184192
}
185193
```
186194

195+
See also:
196+
197+
- [`ErrorBoundary` props][errorboundary-props]
198+
- [`isRouteErorResponse` docs][is-route-error-response]
199+
- [React Error Boundaries docs][error-boundaries]
200+
187201
## `HydrateFallback`
188202

189203
On initial page load, the route component renders only after the client loader is finished. If exported, a `HydrateFallback` can render immediately in place of the route component.
@@ -203,9 +217,13 @@ export default function Component({ loaderData }) {
203217
}
204218
```
205219

220+
See also:
221+
222+
- [`HydrateFallback` props][hydratefallback-props]
223+
206224
## `headers`
207225

208-
Route headers define HTTP headers to be sent with the response when server rendering.
226+
Route headers define HTTP [headers] to be sent with the response when server rendering.
209227

210228
```tsx
211229
export function headers() {
@@ -216,6 +234,11 @@ export function headers() {
216234
}
217235
```
218236

237+
See also:
238+
239+
- [`headers` params][headers-params]
240+
- [`Cache-Control` header][cache-control-header]
241+
219242
## `handle`
220243

221244
Route handle allows apps to add anything to a route match in `useMatches` to create abstractions (like breadcrumbs, etc.).
@@ -226,6 +249,11 @@ export const handle = {
226249
};
227250
```
228251

252+
See also:
253+
254+
- [`handle` docs][handle]
255+
- [`useMatches` docs][use-matches]
256+
229257
## `links`
230258

231259
Route links define [`<link>` element][link-element]s to be rendered in the document `<head>`.
@@ -269,9 +297,13 @@ export default function Root() {
269297
}
270298
```
271299

300+
See also:
301+
302+
- [`links` params][links-params]
303+
272304
## `meta`
273305

274-
Route meta defines meta tags to be rendered in the `<head>` of the document.
306+
Route meta defines [`<meta>`][meta-element] tags to be rendered in the `<head>` of the document.
275307

276308
```tsx
277309
export function meta() {
@@ -307,7 +339,7 @@ export default function Root() {
307339
}
308340
```
309341

310-
**See also**
342+
See also:
311343

312344
- [`meta` params][meta-params]
313345

@@ -325,22 +357,31 @@ export function shouldRevalidate(
325357
}
326358
```
327359

360+
See also:
361+
362+
- [`shouldRevalidate` params][shouldrevalidate-params]
363+
328364
---
329365

330366
Next: [Rendering Strategies](./rendering)
331367

332-
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
333-
[loader-params]: https://api.reactrouter.com/v7/interfaces/react_router.LoaderFunctionArgs
334-
[client-loader-params]: https://api.reactrouter.com/v7/types/react_router.ClientLoaderFunctionArgs
335-
[action-params]: https://api.reactrouter.com/v7/interfaces/react_router.ActionFunctionArgs
336-
[client-action-params]: https://api.reactrouter.com/v7/types/react_router.ClientActionFunctionArgs
337368
[error-boundaries]: https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary
338-
[use-route-error]: https://api.reactrouter.com/v7/functions/react_router.useRouteError
339369
[is-route-error-response]: https://api.reactrouter.com/v7/functions/react_router.isRouteErrorResponse
340370
[cache-control-header]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
341371
[headers]: https://developer.mozilla.org/en-US/docs/Web/API/Response
342372
[use-matches]: https://api.reactrouter.com/v7/functions/react_router.useMatches
343373
[link-element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
344374
[meta-element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
345-
[meta-params]: https://api.reactrouter.com/v7/interfaces/react_router.MetaArgs
346-
[use-revalidator]: https://api.reactrouter.com/v7/functions/react_router.useRevalidator.html
375+
[route-module]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html
376+
[component-props]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#default
377+
[loader-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#loader
378+
[client-loader-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#clientLoader
379+
[action-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#actioin
380+
[client-action-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#clientAction
381+
[meta-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#meta
382+
[links-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#links
383+
[handle]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#handle
384+
[errorboundary-props]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#ErrorBoundary
385+
[hydratefallback-props]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#HydrateFallback
386+
[headers-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#headers
387+
[shouldrevalidate-params]: https://api.reactrouter.com/v7/interfaces/react_router.ServerRouteModule.html#shouldRevalidate

packages/react-router/lib/dom/ssr/routeModules.ts

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ComponentType, ReactElement } from "react";
1+
import type * as React from "react";
22
import type { Location } from "../../router/history";
33
import type {
44
ActionFunction,
@@ -32,16 +32,14 @@ export interface RouteModule {
3232
*/
3333
clientLoader?: ClientLoaderFunction;
3434
/**
35-
* When other route module APIs throw, the route module `ErrorBoundary` will
36-
* render instead of the route component.
35+
* ErrorBoundary to display for this route
3736
*/
38-
ErrorBoundary?: ErrorBoundaryComponent;
37+
ErrorBoundary?: React.ComponentType;
3938
/**
40-
* On initial page load, the route component renders only after the client
41-
* loader is finished. If exported, a `HydrateFallback` can render
42-
* immediately in place of the route component.
39+
* `<Route HydrateFallback>` component to render on initial loads
40+
* when client loaders are present
4341
*/
44-
HydrateFallback?: HydrateFallbackComponent;
42+
HydrateFallback?: React.ComponentType;
4543
/**
4644
* The `Layout` export is only applicable to the root route. Because the root
4745
* route manages the document for all routes, it supports an additional optional
@@ -52,7 +50,7 @@ export interface RouteModule {
5250
/**
5351
* Defines the component that will render when the route matches.
5452
*/
55-
default: RouteComponent;
53+
default: React.ComponentType<{}>;
5654
/**
5755
* Route handle allows apps to add anything to a route match in `useMatches`
5856
* to create abstractions (like breadcrumbs, etc.).
@@ -126,11 +124,6 @@ export type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
126124
serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
127125
};
128126

129-
/**
130-
* ErrorBoundary to display for this route
131-
*/
132-
export type ErrorBoundaryComponent = ComponentType;
133-
134127
/**
135128
* Parameters passed to the [`headers`]{@link HeadersFunction} function
136129
*/
@@ -149,22 +142,13 @@ export interface HeadersFunction {
149142
(args: HeadersArgs): Headers | HeadersInit;
150143
}
151144

152-
/**
153-
* `<Route HydrateFallback>` component to render on initial loads
154-
* when client loaders are present
155-
*/
156-
export type HydrateFallbackComponent = ComponentType;
157-
158145
/**
159146
* Optional, root-only `<Route Layout>` component to wrap the root content in.
160147
* Useful for defining the <html>/<head>/<body> document shell shared by the
161148
* Component, HydrateFallback, and ErrorBoundary
162149
*/
163-
export type LayoutComponent = ComponentType<{
164-
children: ReactElement<
165-
unknown,
166-
ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent
167-
>;
150+
export type LayoutComponent = React.ComponentType<{
151+
children: React.ReactElement;
168152
}>;
169153

170154
/**
@@ -301,11 +285,6 @@ type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
301285
type LdJsonPrimitive = string | number | boolean | null;
302286
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
303287

304-
/**
305-
* A React component that is rendered for a route.
306-
*/
307-
export type RouteComponent = ComponentType<{}>;
308-
309288
/**
310289
* An arbitrary object that is associated with a route.
311290
*

0 commit comments

Comments
 (0)