Skip to content

Commit 63808a7

Browse files
committed
docs(api): add some extra reference links
1 parent 3fdce65 commit 63808a7

File tree

14 files changed

+370
-254
lines changed

14 files changed

+370
-254
lines changed

packages/react-router/dom-export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
export type { RouterProviderProps } from "./lib/dom-export/dom-router-provider";
44
export { RouterProvider } from "./lib/dom-export/dom-router-provider";
5+
export type { HydratedRouterProps } from "./lib/dom-export/hydrated-router";
56
export { HydratedRouter } from "./lib/dom-export/hydrated-router";

packages/react-router/lib/components.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ export interface MemoryRouterProps {
580580
* @param {MemoryRouterProps.children} props.children n/a
581581
* @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
582582
* @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
583-
* @returns A declarative in memory router for client side routing.
583+
* @returns A declarative in-memory {@link Router | `<Router>`} for client-side
584+
* routing.
584585
*/
585586
export function MemoryRouter({
586587
basename,
@@ -1007,7 +1008,7 @@ export interface RouterProps {
10071008
*/
10081009
location: Partial<Location> | string;
10091010
/**
1010-
* The type of navigation that triggered this location change.
1011+
* The type of navigation that triggered this `location` change.
10111012
* Defaults to {@link NavigationType.Pop}.
10121013
*/
10131014
navigationType?: NavigationType;

packages/react-router/lib/dom-export/hydrated-router.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,30 @@ function createHydratedRouter({
209209
return router;
210210
}
211211

212-
interface HydratedRouterProps {
212+
/**
213+
* Props for the {@link HydratedRouter} component.
214+
*
215+
* @category Types
216+
*/
217+
export interface HydratedRouterProps {
213218
/**
214-
* Context object to passed through to `createBrowserRouter` and made available
215-
* to `clientLoader`/`clientActon` functions
219+
* Context object to be passed through to {@link createBrowserRouter} and made
220+
* available to
221+
* [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
222+
* functions
216223
*/
217224
unstable_getContext?: RouterInit["unstable_getContext"];
218225
}
219226

220227
/**
221-
* Framework-mode router component to be used to to hydrate a router from a
222-
* `ServerRouter`. See [`entry.client.tsx`](../api/framework-conventions/entry.client.tsx).
228+
* Framework-mode router component to be used to hydrate a router from a
229+
* {@link ServerRouter}. See [`entry.client.tsx`](../framework-conventions/entry.client.tsx).
223230
*
224231
* @public
225232
* @category Framework Routers
226233
* @mode framework
227234
* @param props Props
228-
* @param props.unstable_getContext Context object to passed through to
229-
* {@link createBrowserRouter} and made available to `clientLoader`/`clientAction`
230-
* functions
235+
* @param {HydratedRouterProps.unstable_getContext} props.unstable_getContext n/a
231236
* @returns A React element that represents the hydrated application.
232237
*/
233238
export function HydratedRouter(props: HydratedRouterProps) {

packages/react-router/lib/dom/lib.tsx

Lines changed: 132 additions & 109 deletions
Large diffs are not rendered by default.

packages/react-router/lib/dom/server.tsx

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,36 @@ import {
3636
} from "../context";
3737
import { useRoutesImpl } from "../hooks";
3838

39+
/**
40+
* @category Types
41+
*/
3942
export interface StaticRouterProps {
43+
/**
44+
* The base URL for the static router (default: `/`)
45+
*/
4046
basename?: string;
47+
/**
48+
* The child elements to render inside the static router
49+
*/
4150
children?: React.ReactNode;
51+
/**
52+
* The {@link Location} to render the static router at (default: `/`)
53+
*/
4254
location: Partial<Location> | string;
4355
}
4456

4557
/**
46-
* A `<Router>` that may not navigate to any other location. This is useful
47-
* on the server where there is no stateful UI.
58+
* A {@link Router | `<Router>`} that may not navigate to any other {@link Location}.
59+
* This is useful on the server where there is no stateful UI.
4860
*
4961
* @public
5062
* @category Declarative Routers
5163
* @mode declarative
5264
* @param props Props
53-
* @param props.basename The base URL for the static router (default: `/`)
54-
* @param props.children The child elements to render inside the static router
55-
* @param props.location The location to render the static router at (default: `/`)
56-
* @returns A React element that renders the static router
65+
* @param {StaticRouterProps.basename} props.basename n/a
66+
* @param {StaticRouterProps.children} props.children n/a
67+
* @param {StaticRouterProps.location} props.location n/a
68+
* @returns A React element that renders the static {@link Router | `<Router>`}
5769
*/
5870
export function StaticRouter({
5971
basename,
@@ -86,16 +98,34 @@ export function StaticRouter({
8698
);
8799
}
88100

101+
/**
102+
* @category Types
103+
*/
89104
export interface StaticRouterProviderProps {
105+
/**
106+
* The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
107+
* `query`
108+
*/
90109
context: StaticHandlerContext;
110+
/**
111+
* The static {@link DataRouter} from {@link createStaticRouter}
112+
*/
91113
router: DataRouter;
114+
/**
115+
* Whether to hydrate the router on the client (default `true`)
116+
*/
92117
hydrate?: boolean;
118+
/**
119+
* The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
120+
* to use for the hydration [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
121+
* tag
122+
*/
93123
nonce?: string;
94124
}
95125

96126
/**
97-
* A Data Router that may not navigate to any other location. This is useful
98-
* on the server where there is no stateful UI.
127+
* A {@link DataRouter} that may not navigate to any other {@link Location}.
128+
* This is useful on the server where there is no stateful UI.
99129
*
100130
* @example
101131
* export async function handleRequest(request: Request) {
@@ -117,11 +147,10 @@ export interface StaticRouterProviderProps {
117147
* @category Data Routers
118148
* @mode data
119149
* @param props Props
120-
* @param props.context The {@link StaticHandlerContext} returned from `staticHandler.query()`
121-
* @param props.router The static data router from {@link createStaticRouter}
122-
* @param props.hydrate Whether to hydrate the router on the client (default `true`)
123-
* @param props.nonce The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
124-
* to use for the hydration `<script>` tag
150+
* @param {StaticRouterProviderProps.context} props.context n/a
151+
* @param {StaticRouterProviderProps.hydrate} props.hydrate n/a
152+
* @param {StaticRouterProviderProps.nonce} props.nonce n/a
153+
* @param {StaticRouterProviderProps.router} props.router n/a
125154
* @returns A React element that renders the static router provider
126155
*/
127156
export function StaticRouterProvider({
@@ -292,7 +321,7 @@ type CreateStaticHandlerOptions = Omit<
292321
* @example
293322
* export async function handleRequest(request: Request) {
294323
* let { query, dataRoutes } = createStaticHandler(routes);
295-
* let context = await query(request));
324+
* let context = await query(request);
296325
*
297326
* if (context instanceof Response) {
298327
* return context;
@@ -308,11 +337,13 @@ type CreateStaticHandlerOptions = Omit<
308337
* @public
309338
* @category Data Routers
310339
* @mode data
311-
* @param routes The route objects to create a static handler for
340+
* @param routes The {@link RouteObject | route objects} to create a static
341+
* handler for
312342
* @param opts Options
313343
* @param opts.basename The base URL for the static handler (default: `/`)
314344
* @param opts.future Future flags for the static handler
315-
* @returns A static handler that can be used to query data for the provided routes
345+
* @returns A static handler that can be used to query data for the provided
346+
* routes
316347
*/
317348
export function createStaticHandler(
318349
routes: RouteObject[],
@@ -325,12 +356,12 @@ export function createStaticHandler(
325356
}
326357

327358
/**
328-
* Create a static data router for server-side rendering
359+
* Create a static {@link DataRouter} for server-side rendering
329360
*
330361
* @example
331362
* export async function handleRequest(request: Request) {
332363
* let { query, dataRoutes } = createStaticHandler(routes);
333-
* let context = await query(request));
364+
* let context = await query(request);
334365
*
335366
* if (context instanceof Response) {
336367
* return context;
@@ -346,11 +377,12 @@ export function createStaticHandler(
346377
* @public
347378
* @category Data Routers
348379
* @mode data
349-
* @param routes The route objects to create a static data router for
350-
* @param context The static handler context returned from `staticHandler.query()`
380+
* @param routes The route objects to create a static {@link DataRouter} for
381+
* @param context The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
382+
* `query`
351383
* @param opts Options
352-
* @param opts.future Future flags for the static data router
353-
* @returns A static data router that can be used to render the provided routes
384+
* @param opts.future Future flags for the static {@link DataRouter}
385+
* @returns A static {@link DataRouter} that can be used to render the provided routes
354386
*/
355387
export function createStaticRouter(
356388
routes: RouteObject[],

packages/react-router/lib/dom/ssr/components.tsx

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ function getActiveMatches(
215215
export const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
216216

217217
/**
218-
* Renders all of the `<link>` tags created by the route module
219-
* [`links`](../../start/framework/route-module#links) export. You should render
220-
* it inside the `<head>` of your document.
218+
* Renders all the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
219+
* tags created by the route module's [`links`](../../start/framework/route-module#links)
220+
* export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
221+
* of your document.
221222
*
222223
* @example
223224
* import { Links } from "react-router";
@@ -236,7 +237,8 @@ export const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
236237
* @public
237238
* @category Components
238239
* @mode framework
239-
* @returns A collection of React elements for `<link>` tags
240+
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
241+
* tags
240242
*/
241243
export function Links(): React.JSX.Element {
242244
let { isSpaMode, manifest, routeModules, criticalCss } =
@@ -277,10 +279,10 @@ export function Links(): React.JSX.Element {
277279
}
278280

279281
/**
280-
* Renders `<link rel=prefetch|modulepreload>` tags for modules and data of
281-
* another page to enable an instant navigation to that page.
282-
* [`<Link prefetch>`](../../components/Link#prefetch) uses this internally, but
283-
* you can render it to prefetch a page for any other reason.
282+
* Renders [`<link rel=prefetch|modulepreload>`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel)
283+
* tags for modules and data of another page to enable an instant navigation to
284+
* that page. [`<Link prefetch>`](./Link#prefetch) uses this internally, but you
285+
* can render it to prefetch a page for any other reason.
284286
*
285287
* For example, you may render one of this as the user types into a search field
286288
* to prefetch search results before they click through to their selection.
@@ -296,9 +298,13 @@ export function Links(): React.JSX.Element {
296298
* @param props Props
297299
* @param props.page The absolute path of the page to prefetch, e.g. `/absolute/path`.
298300
* @param props.dataLinkProps Additional props to pass to the
299-
* [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link)
300-
* tag, such as `crossOrigin`, `integrity`, `rel`, etc.
301-
* @returns A collection of React elements for `<link>` tags
301+
* [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
302+
* tag, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin),
303+
* [`integrity`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/integrity),
304+
* [`rel`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel),
305+
* etc.
306+
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
307+
* tags
302308
*/
303309
export function PrefetchPageLinks({
304310
page,
@@ -470,9 +476,10 @@ function PrefetchPageLinksImpl({
470476
}
471477

472478
/**
473-
* Renders all the `<meta>` tags created by the route module
474-
* [`meta`](../../start/framework/route-module#meta) exports. You should render
475-
* it inside the `<head>` of your HTML.
479+
* Renders all the [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
480+
* tags created by the route module's [`meta`](../../start/framework/route-module#meta)
481+
* export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
482+
* of your document.
476483
*
477484
* @example
478485
* import { Meta } from "react-router";
@@ -490,7 +497,8 @@ function PrefetchPageLinksImpl({
490497
* @public
491498
* @category Components
492499
* @mode framework
493-
* @returns A collection of React elements for `<meta>` tags
500+
* @returns A collection of React elements for [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
501+
* tags
494502
*/
495503
export function Meta(): React.JSX.Element {
496504
let { isSpaMode, routeModules } = useFrameworkContext();
@@ -634,10 +642,19 @@ let isHydrated = false;
634642
/**
635643
* A couple common attributes:
636644
*
637-
* - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
638-
* - `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) for your `<script>` tags.
645+
* - `<Scripts crossOrigin>` for hosting your static assets on a different
646+
* server than your app.
647+
* - `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src)
648+
* with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources)
649+
* for your [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
650+
* tags.
639651
*
640-
* You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
652+
* You cannot pass through attributes such as [`async`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async),
653+
* [`defer`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/defer),
654+
* [`noModule`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule),
655+
* [`src`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src),
656+
* or [`type`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type),
657+
* because they are managed by React Router internally.
641658
*
642659
* @category Types
643660
*/
@@ -647,21 +664,22 @@ export type ScriptsProps = Omit<
647664
| "children"
648665
| "dangerouslySetInnerHTML"
649666
| "defer"
650-
| "src"
651-
| "type"
652667
| "noModule"
668+
| "src"
653669
| "suppressHydrationWarning"
670+
| "type"
654671
> & {
655672
/**
656673
* A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
657-
* attribute to render on [the `<script>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script)
674+
* attribute to render on the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
675+
* element
658676
*/
659677
nonce?: string | undefined;
660678
};
661679

662680
/**
663681
* Renders the client runtime of your app. It should be rendered inside the
664-
* [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/body)
682+
* [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
665683
* of the document.
666684
*
667685
* If server rendering, you can omit `<Scripts/>` and the app will work as a
@@ -686,9 +704,12 @@ export type ScriptsProps = Omit<
686704
* @category Components
687705
* @mode framework
688706
* @param props Props for the
689-
* [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script)
690-
* tag, such as `crossOrigin`, `nonce`, etc.
691-
* @returns A collection of React elements for `<script>` tags
707+
* [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
708+
* tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin),
709+
* [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce),
710+
* etc.
711+
* @returns A collection of React elements for [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
712+
* tags
692713
*/
693714
export function Scripts(props: ScriptsProps): React.JSX.Element | null {
694715
let {

0 commit comments

Comments
 (0)