Skip to content

Commit 8879508

Browse files
docs(api): add some extra reference links (#14024)
1 parent 9fde466 commit 8879508

File tree

15 files changed

+464
-311
lines changed

15 files changed

+464
-311
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/dom-router-provider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import * as ReactDOM from "react-dom";
44
import type { RouterProviderProps as BaseRouterProviderProps } from "react-router";
55
import { RouterProvider as BaseRouterProvider } from "react-router";
66

7+
// FIXME: We now have two `RouterProviderProps` type, one in `react-router` and
8+
// one in `react-router/dom`.
79
export type RouterProviderProps = Omit<BaseRouterProviderProps, "flushSync">;
810

11+
// FIXME: We now have two `RouterProvider` components, one in `react-router` and
12+
// one in `react-router/dom`.
913
export function RouterProvider(props: Omit<RouterProviderProps, "flushSync">) {
1014
return <BaseRouterProvider flushSync={ReactDOM.flushSync} {...props} />;
1115
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,34 @@ 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

227+
// TODO: Reference `HydratedRouterProps` in the `HydratedRouter` JSDoc
228+
// @param {HydratedRouterProps.unstable_getContext} props.unstable_getContext n/a
220229
/**
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).
230+
* Framework-mode router component to be used to hydrate a router from a
231+
* {@link ServerRouter}. See [`entry.client.tsx`](../framework-conventions/entry.client.tsx).
223232
*
224233
* @public
225234
* @category Framework Routers
226235
* @mode framework
227236
* @param props Props
228-
* @param props.unstable_getContext Context object to passed through to
229-
* {@link createBrowserRouter} and made available to `clientLoader`/`clientAction`
237+
* @param props.unstable_getContext Context object to be passed through to
238+
* {@link createBrowserRouter} and made available to
239+
* [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
230240
* functions
231241
* @returns A React element that represents the hydrated application.
232242
*/

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

Lines changed: 196 additions & 146 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: 47 additions & 28 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.
@@ -294,11 +296,14 @@ export function Links(): React.JSX.Element {
294296
* @category Components
295297
* @mode framework
296298
* @param props Props
297-
* @param props.page The absolute path of the page to prefetch, e.g. `/absolute/path`.
298-
* @param props.linkProps Additional props to spread onto the
299-
* [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link)
300-
* tags, such as `crossOrigin`, `integrity`, `rel`, etc.
301-
* @returns A collection of React elements for `<link>` tags
299+
* @param {PageLinkDescriptor.page} props.page n/a
300+
* @param props.linkProps Additional props to spread onto the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
301+
* tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin),
302+
* [`integrity`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/integrity),
303+
* [`rel`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel),
304+
* etc.
305+
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
306+
* tags
302307
*/
303308
export function PrefetchPageLinks({ page, ...linkProps }: PageLinkDescriptor) {
304309
let { router } = useDataRouterContext();
@@ -465,9 +470,10 @@ function PrefetchPageLinksImpl({
465470
}
466471

467472
/**
468-
* Renders all the `<meta>` tags created by the route module
469-
* [`meta`](../../start/framework/route-module#meta) exports. You should render
470-
* it inside the `<head>` of your HTML.
473+
* Renders all the [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
474+
* tags created by the route module's [`meta`](../../start/framework/route-module#meta)
475+
* export. You should render it inside the [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
476+
* of your document.
471477
*
472478
* @example
473479
* import { Meta } from "react-router";
@@ -485,7 +491,8 @@ function PrefetchPageLinksImpl({
485491
* @public
486492
* @category Components
487493
* @mode framework
488-
* @returns A collection of React elements for `<meta>` tags
494+
* @returns A collection of React elements for [`<meta>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta)
495+
* tags
489496
*/
490497
export function Meta(): React.JSX.Element {
491498
let { isSpaMode, routeModules } = useFrameworkContext();
@@ -629,10 +636,19 @@ let isHydrated = false;
629636
/**
630637
* A couple common attributes:
631638
*
632-
* - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
633-
* - `<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.
639+
* - `<Scripts crossOrigin>` for hosting your static assets on a different
640+
* server than your app.
641+
* - `<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)
642+
* with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources)
643+
* for your [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
644+
* tags.
634645
*
635-
* You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
646+
* You cannot pass through attributes such as [`async`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async),
647+
* [`defer`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/defer),
648+
* [`noModule`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule),
649+
* [`src`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src),
650+
* or [`type`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type),
651+
* because they are managed by React Router internally.
636652
*
637653
* @category Types
638654
*/
@@ -642,21 +658,22 @@ export type ScriptsProps = Omit<
642658
| "children"
643659
| "dangerouslySetInnerHTML"
644660
| "defer"
645-
| "src"
646-
| "type"
647661
| "noModule"
662+
| "src"
648663
| "suppressHydrationWarning"
664+
| "type"
649665
> & {
650666
/**
651667
* A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
652-
* attribute to render on [the `<script>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script)
668+
* attribute to render on the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
669+
* element
653670
*/
654671
nonce?: string | undefined;
655672
};
656673

657674
/**
658675
* Renders the client runtime of your app. It should be rendered inside the
659-
* [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/body)
676+
* [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
660677
* of the document.
661678
*
662679
* If server rendering, you can omit `<Scripts/>` and the app will work as a
@@ -680,10 +697,12 @@ export type ScriptsProps = Omit<
680697
* @public
681698
* @category Components
682699
* @mode framework
683-
* @param scriptProps Additional props to spread onto the
684-
* [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script)
685-
* tag, such as `crossOrigin`, `nonce`, etc.
686-
* @returns A collection of React elements for `<script>` tags
700+
* @param scriptProps Additional props to spread onto the [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
701+
* tags, such as [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin),
702+
* [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce),
703+
* etc.
704+
* @returns A collection of React elements for [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
705+
* tags
687706
*/
688707
export function Scripts(scriptProps: ScriptsProps): React.JSX.Element | null {
689708
let {

0 commit comments

Comments
 (0)