react-router 7.7.0 → 7.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +11 -23
  2. package/dist/development/{browser-CcxeZJcQ.d.mts → browser-7LYX59NK.d.mts} +97 -1
  3. package/dist/development/{chunk-EF7DTUVF.mjs → chunk-C37GKA54.mjs} +83 -80
  4. package/dist/development/{chunk-V6PEDDZI.js → chunk-K7YFBME3.js} +79 -76
  5. package/dist/{production/chunk-GNZILI6H.mjs → development/chunk-KIUJAIYX.mjs} +3 -5
  6. package/dist/{production/chunk-2TYFPE3B.js → development/chunk-R73PQUJU.js} +132 -132
  7. package/dist/development/components-CjQijYga.d.mts +802 -0
  8. package/dist/development/dom-export.d.mts +13 -6
  9. package/dist/development/dom-export.d.ts +10 -3
  10. package/dist/development/dom-export.js +3 -3
  11. package/dist/development/dom-export.mjs +3 -3
  12. package/dist/development/index-react-server-client-Bi_fx8qz.d.ts +3163 -0
  13. package/dist/development/index-react-server-client-KLg-U4nr.d.mts +2366 -0
  14. package/dist/development/index-react-server-client.d.mts +3 -3
  15. package/dist/development/index-react-server-client.d.ts +2 -2
  16. package/dist/development/index-react-server-client.js +4 -4
  17. package/dist/development/index-react-server-client.mjs +2 -2
  18. package/dist/development/index-react-server.d.mts +109 -2
  19. package/dist/development/index-react-server.d.ts +109 -2
  20. package/dist/development/index-react-server.js +28 -20
  21. package/dist/development/index-react-server.mjs +29 -21
  22. package/dist/development/index.d.mts +918 -287
  23. package/dist/development/index.d.ts +1010 -283
  24. package/dist/development/index.js +98 -100
  25. package/dist/development/index.mjs +3 -3
  26. package/dist/development/lib/types/internal.d.mts +1 -1
  27. package/dist/development/lib/types/internal.d.ts +1 -1
  28. package/dist/development/lib/types/internal.js +1 -1
  29. package/dist/development/lib/types/internal.mjs +1 -1
  30. package/dist/{production/route-data-DjzmHYNR.d.mts → development/route-data-CqEmXQub.d.mts} +48 -2
  31. package/dist/{production/routeModules-g5PTiDfO.d.ts → development/routeModules-BR2FO0ix.d.ts} +48 -2
  32. package/dist/production/{browser-CcxeZJcQ.d.mts → browser-7LYX59NK.d.mts} +97 -1
  33. package/dist/{development/chunk-4ADB4KIO.js → production/chunk-4DGLNKXF.js} +132 -132
  34. package/dist/production/{chunk-5KHO4FML.js → chunk-7OQROU2D.js} +79 -76
  35. package/dist/production/{chunk-WPPIQDYG.mjs → chunk-IZ57JD2V.mjs} +83 -80
  36. package/dist/{development/chunk-T3VM44WY.mjs → production/chunk-K3SBCRK4.mjs} +3 -5
  37. package/dist/production/components-CjQijYga.d.mts +802 -0
  38. package/dist/production/dom-export.d.mts +13 -6
  39. package/dist/production/dom-export.d.ts +10 -3
  40. package/dist/production/dom-export.js +3 -3
  41. package/dist/production/dom-export.mjs +3 -3
  42. package/dist/production/index-react-server-client-Bi_fx8qz.d.ts +3163 -0
  43. package/dist/production/index-react-server-client-KLg-U4nr.d.mts +2366 -0
  44. package/dist/production/index-react-server-client.d.mts +3 -3
  45. package/dist/production/index-react-server-client.d.ts +2 -2
  46. package/dist/production/index-react-server-client.js +4 -4
  47. package/dist/production/index-react-server-client.mjs +2 -2
  48. package/dist/production/index-react-server.d.mts +109 -2
  49. package/dist/production/index-react-server.d.ts +109 -2
  50. package/dist/production/index-react-server.js +28 -20
  51. package/dist/production/index-react-server.mjs +29 -21
  52. package/dist/production/index.d.mts +918 -287
  53. package/dist/production/index.d.ts +1010 -283
  54. package/dist/production/index.js +98 -100
  55. package/dist/production/index.mjs +3 -3
  56. package/dist/production/lib/types/internal.d.mts +1 -1
  57. package/dist/production/lib/types/internal.d.ts +1 -1
  58. package/dist/production/lib/types/internal.js +1 -1
  59. package/dist/production/lib/types/internal.mjs +1 -1
  60. package/dist/{development/route-data-DjzmHYNR.d.mts → production/route-data-CqEmXQub.d.mts} +48 -2
  61. package/dist/{development/routeModules-g5PTiDfO.d.ts → production/routeModules-BR2FO0ix.d.ts} +48 -2
  62. package/package.json +1 -1
  63. package/dist/development/components-DzqPLVI1.d.mts +0 -464
  64. package/dist/development/index-react-server-client-CUidsuu_.d.mts +0 -1360
  65. package/dist/development/index-react-server-client-kY8DvDF3.d.ts +0 -1819
  66. package/dist/production/components-DzqPLVI1.d.mts +0 -464
  67. package/dist/production/index-react-server-client-CUidsuu_.d.mts +0 -1360
  68. package/dist/production/index-react-server-client-kY8DvDF3.d.ts +0 -1819
@@ -1,1819 +0,0 @@
1
- import { I as InitialEntry, T as To, i as RelativeRoutingType, w as NonIndexRouteObject, ag as LazyRouteFunction, q as IndexRouteObject, a as Location, A as Action, aD as Navigator, d as Router$1, V as RouterInit, aZ as FutureConfig$1, H as HydrationState, D as DataStrategyFunction, X as PatchRoutesOnNavigationFunction, p as RouteObject, aF as RouteMatch, o as Params, U as UIMatch, af as HTMLFormMethod, ad as FormEncType, a_ as RouteManifest, a$ as ServerRouteModule, z as MiddlewareEnabled, y as unstable_RouterContextProvider, x as AppLoadContext, ah as LoaderFunctionArgs, a7 as ActionFunctionArgs, e as RouteModules, Y as DataRouteObject, K as ClientLoaderFunction, a0 as StaticHandlerContext, aK as PageLinkDescriptor, b0 as History, $ as GetScrollRestorationKeyFunction, f as NavigateOptions, a1 as Fetcher, h as SerializeFrom, B as BlockerFunction, b1 as CreateStaticHandlerOptions$1, Z as StaticHandler } from './routeModules-g5PTiDfO.js';
2
- import * as React from 'react';
3
-
4
- /**
5
- * @private
6
- */
7
- declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
8
- hasErrorBoundary: boolean;
9
- };
10
- declare const hydrationRouteProperties: (keyof RouteObject)[];
11
- interface MemoryRouterOpts {
12
- /**
13
- * Basename path for the application.
14
- */
15
- basename?: string;
16
- /**
17
- * Function to provide the initial context values for all client side navigations/fetches
18
- */
19
- unstable_getContext?: RouterInit["unstable_getContext"];
20
- /**
21
- * Future flags to enable for the router.
22
- */
23
- future?: Partial<FutureConfig$1>;
24
- /**
25
- * Hydration data to initialize the router with if you have already performed
26
- * data loading on the server.
27
- */
28
- hydrationData?: HydrationState;
29
- /**
30
- * Initial entires in the in-memory history stack
31
- */
32
- initialEntries?: InitialEntry[];
33
- /**
34
- * Index of `initialEntries` the application should initialize to
35
- */
36
- initialIndex?: number;
37
- /**
38
- * Override the default data strategy of loading in parallel.
39
- * Only intended for advanced usage.
40
- */
41
- dataStrategy?: DataStrategyFunction;
42
- /**
43
- * Lazily define portions of the route tree on navigations.
44
- */
45
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
46
- }
47
- /**
48
- * Create a new data router that manages the application path using an in-memory
49
- * history stack. Useful for non-browser environments without a DOM API.
50
- *
51
- * @category Data Routers
52
- */
53
- declare function createMemoryRouter(
54
- /**
55
- * Application routes
56
- */
57
- routes: RouteObject[],
58
- /**
59
- * Router options
60
- */
61
- opts?: MemoryRouterOpts): Router$1;
62
- interface RouterProviderProps {
63
- router: Router$1;
64
- flushSync?: (fn: () => unknown) => undefined;
65
- }
66
- /**
67
- * Given a Remix Router instance, render the appropriate UI
68
- */
69
- declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, }: RouterProviderProps): React.ReactElement;
70
- /**
71
- * @category Types
72
- */
73
- interface MemoryRouterProps {
74
- basename?: string;
75
- children?: React.ReactNode;
76
- initialEntries?: InitialEntry[];
77
- initialIndex?: number;
78
- }
79
- /**
80
- * A `<Router>` that stores all entries in memory.
81
- *
82
- * @category Component Routers
83
- */
84
- declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
85
- /**
86
- * @category Types
87
- */
88
- interface NavigateProps {
89
- to: To;
90
- replace?: boolean;
91
- state?: any;
92
- relative?: RelativeRoutingType;
93
- }
94
- /**
95
- * A component-based version of {@link useNavigate} to use in a [`React.Component
96
- * Class`](https://reactjs.org/docs/react-component.html) where hooks are not
97
- * able to be used.
98
- *
99
- * It's recommended to avoid using this component in favor of {@link useNavigate}
100
- *
101
- * @category Components
102
- */
103
- declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
104
- /**
105
- * @category Types
106
- */
107
- interface OutletProps {
108
- /**
109
- Provides a context value to the element tree below the outlet. Use when the parent route needs to provide values to child routes.
110
-
111
- ```tsx
112
- <Outlet context={myContextValue} />
113
- ```
114
-
115
- Access the context with {@link useOutletContext}.
116
- */
117
- context?: unknown;
118
- }
119
- /**
120
- Renders the matching child route of a parent route or nothing if no child route matches.
121
-
122
- ```tsx
123
- import { Outlet } from "react-router"
124
-
125
- export default function SomeParent() {
126
- return (
127
- <div>
128
- <h1>Parent Content</h1>
129
- <Outlet />
130
- </div>
131
- );
132
- }
133
- ```
134
-
135
- @category Components
136
- */
137
- declare function Outlet(props: OutletProps): React.ReactElement | null;
138
- /**
139
- * @category Types
140
- */
141
- interface PathRouteProps {
142
- caseSensitive?: NonIndexRouteObject["caseSensitive"];
143
- path?: NonIndexRouteObject["path"];
144
- id?: NonIndexRouteObject["id"];
145
- lazy?: LazyRouteFunction<NonIndexRouteObject>;
146
- loader?: NonIndexRouteObject["loader"];
147
- action?: NonIndexRouteObject["action"];
148
- hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
149
- shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
150
- handle?: NonIndexRouteObject["handle"];
151
- index?: false;
152
- children?: React.ReactNode;
153
- element?: React.ReactNode | null;
154
- hydrateFallbackElement?: React.ReactNode | null;
155
- errorElement?: React.ReactNode | null;
156
- Component?: React.ComponentType | null;
157
- HydrateFallback?: React.ComponentType | null;
158
- ErrorBoundary?: React.ComponentType | null;
159
- }
160
- /**
161
- * @category Types
162
- */
163
- interface LayoutRouteProps extends PathRouteProps {
164
- }
165
- /**
166
- * @category Types
167
- */
168
- interface IndexRouteProps {
169
- caseSensitive?: IndexRouteObject["caseSensitive"];
170
- path?: IndexRouteObject["path"];
171
- id?: IndexRouteObject["id"];
172
- lazy?: LazyRouteFunction<IndexRouteObject>;
173
- loader?: IndexRouteObject["loader"];
174
- action?: IndexRouteObject["action"];
175
- hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
176
- shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
177
- handle?: IndexRouteObject["handle"];
178
- index: true;
179
- children?: undefined;
180
- element?: React.ReactNode | null;
181
- hydrateFallbackElement?: React.ReactNode | null;
182
- errorElement?: React.ReactNode | null;
183
- Component?: React.ComponentType | null;
184
- HydrateFallback?: React.ComponentType | null;
185
- ErrorBoundary?: React.ComponentType | null;
186
- }
187
- type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
188
- /**
189
- * Configures an element to render when a pattern matches the current location.
190
- * It must be rendered within a {@link Routes} element. Note that these routes
191
- * do not participate in data loading, actions, code splitting, or any other
192
- * route module features.
193
- *
194
- * @category Components
195
- */
196
- declare function Route$1(_props: RouteProps): React.ReactElement | null;
197
- /**
198
- * @category Types
199
- */
200
- interface RouterProps {
201
- basename?: string;
202
- children?: React.ReactNode;
203
- location: Partial<Location> | string;
204
- navigationType?: Action;
205
- navigator: Navigator;
206
- static?: boolean;
207
- }
208
- /**
209
- * Provides location context for the rest of the app.
210
- *
211
- * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
212
- * router that is more specific to your environment such as a `<BrowserRouter>`
213
- * in web browsers or a `<StaticRouter>` for server rendering.
214
- *
215
- * @category Components
216
- */
217
- declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
218
- /**
219
- * @category Types
220
- */
221
- interface RoutesProps {
222
- /**
223
- * Nested {@link Route} elements
224
- */
225
- children?: React.ReactNode;
226
- /**
227
- * The location to match against. Defaults to the current location.
228
- */
229
- location?: Partial<Location> | string;
230
- }
231
- /**
232
- Renders a branch of {@link Route | `<Routes>`} that best matches the current
233
- location. Note that these routes do not participate in data loading, actions,
234
- code splitting, or any other route module features.
235
-
236
- ```tsx
237
- import { Routes, Route } from "react-router"
238
-
239
- <Routes>
240
- <Route index element={<StepOne />} />
241
- <Route path="step-2" element={<StepTwo />} />
242
- <Route path="step-3" element={<StepThree />}>
243
- </Routes>
244
- ```
245
-
246
- @category Components
247
- */
248
- declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
249
- interface AwaitResolveRenderFunction<Resolve = any> {
250
- (data: Awaited<Resolve>): React.ReactNode;
251
- }
252
- /**
253
- * @category Types
254
- */
255
- interface AwaitProps<Resolve> {
256
- /**
257
- When using a function, the resolved value is provided as the parameter.
258
-
259
- ```tsx [2]
260
- <Await resolve={reviewsPromise}>
261
- {(resolvedReviews) => <Reviews items={resolvedReviews} />}
262
- </Await>
263
- ```
264
-
265
- When using React elements, {@link useAsyncValue} will provide the
266
- resolved value:
267
-
268
- ```tsx [2]
269
- <Await resolve={reviewsPromise}>
270
- <Reviews />
271
- </Await>
272
-
273
- function Reviews() {
274
- const resolvedReviews = useAsyncValue()
275
- return <div>...</div>
276
- }
277
- ```
278
- */
279
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
280
- /**
281
- The error element renders instead of the children when the promise rejects.
282
-
283
- ```tsx
284
- <Await
285
- errorElement={<div>Oops</div>}
286
- resolve={reviewsPromise}
287
- >
288
- <Reviews />
289
- </Await>
290
- ```
291
-
292
- To provide a more contextual error, you can use the {@link useAsyncError} in a
293
- child component
294
-
295
- ```tsx
296
- <Await
297
- errorElement={<ReviewsError />}
298
- resolve={reviewsPromise}
299
- >
300
- <Reviews />
301
- </Await>
302
-
303
- function ReviewsError() {
304
- const error = useAsyncError()
305
- return <div>Error loading reviews: {error.message}</div>
306
- }
307
- ```
308
-
309
- If you do not provide an errorElement, the rejected value will bubble up to
310
- the nearest route-level {@link NonIndexRouteObject#ErrorBoundary | ErrorBoundary} and be accessible
311
- via {@link useRouteError} hook.
312
- */
313
- errorElement?: React.ReactNode;
314
- /**
315
- Takes a promise returned from a {@link LoaderFunction | loader} value to be resolved and rendered.
316
-
317
- ```jsx
318
- import { useLoaderData, Await } from "react-router"
319
-
320
- export async function loader() {
321
- let reviews = getReviews() // not awaited
322
- let book = await getBook()
323
- return {
324
- book,
325
- reviews, // this is a promise
326
- }
327
- }
328
-
329
- export default function Book() {
330
- const {
331
- book,
332
- reviews, // this is the same promise
333
- } = useLoaderData()
334
-
335
- return (
336
- <div>
337
- <h1>{book.title}</h1>
338
- <p>{book.description}</p>
339
- <React.Suspense fallback={<ReviewsSkeleton />}>
340
- <Await
341
- // and is the promise we pass to Await
342
- resolve={reviews}
343
- >
344
- <Reviews />
345
- </Await>
346
- </React.Suspense>
347
- </div>
348
- );
349
- }
350
- ```
351
- */
352
- resolve: Resolve;
353
- }
354
- /**
355
- Used to render promise values with automatic error handling.
356
-
357
- ```tsx
358
- import { Await, useLoaderData } from "react-router";
359
-
360
- export function loader() {
361
- // not awaited
362
- const reviews = getReviews()
363
- // awaited (blocks the transition)
364
- const book = await fetch("/api/book").then((res) => res.json())
365
- return { book, reviews }
366
- }
367
-
368
- function Book() {
369
- const { book, reviews } = useLoaderData();
370
- return (
371
- <div>
372
- <h1>{book.title}</h1>
373
- <p>{book.description}</p>
374
- <React.Suspense fallback={<ReviewsSkeleton />}>
375
- <Await
376
- resolve={reviews}
377
- errorElement={
378
- <div>Could not load reviews 😬</div>
379
- }
380
- children={(resolvedReviews) => (
381
- <Reviews items={resolvedReviews} />
382
- )}
383
- />
384
- </React.Suspense>
385
- </div>
386
- );
387
- }
388
- ```
389
-
390
- **Note:** `<Await>` expects to be rendered inside of a `<React.Suspense>`
391
-
392
- @category Components
393
-
394
- */
395
- declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
396
- /**
397
- * Creates a route config from a React "children" object, which is usually
398
- * either a `<Route>` element or an array of them. Used internally by
399
- * `<Routes>` to create a route config from its children.
400
- *
401
- * @category Utils
402
- */
403
- declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
404
- /**
405
- * Create route objects from JSX elements instead of arrays of objects
406
- */
407
- declare let createRoutesFromElements: typeof createRoutesFromChildren;
408
- /**
409
- * Renders the result of `matchRoutes()` into a React element.
410
- *
411
- * @category Utils
412
- */
413
- declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
414
- declare function useRouteComponentProps(): {
415
- params: Readonly<Params<string>>;
416
- loaderData: any;
417
- actionData: any;
418
- matches: UIMatch<unknown, unknown>[];
419
- };
420
- type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
421
- type RouteComponentType = React.ComponentType<RouteComponentProps>;
422
- declare function WithComponentProps({ children, }: {
423
- children: React.ReactElement;
424
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
425
- declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
426
- params: Readonly<Params<string>>;
427
- loaderData: any;
428
- actionData: any;
429
- matches: UIMatch<unknown, unknown>[];
430
- }, string | React.JSXElementConstructor<any>>;
431
- declare function useHydrateFallbackProps(): {
432
- params: Readonly<Params<string>>;
433
- loaderData: any;
434
- actionData: any;
435
- };
436
- type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
437
- type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
438
- declare function WithHydrateFallbackProps({ children, }: {
439
- children: React.ReactElement;
440
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
441
- declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
442
- params: Readonly<Params<string>>;
443
- loaderData: any;
444
- actionData: any;
445
- }, string | React.JSXElementConstructor<any>>;
446
- declare function useErrorBoundaryProps(): {
447
- params: Readonly<Params<string>>;
448
- loaderData: any;
449
- actionData: any;
450
- error: unknown;
451
- };
452
- type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
453
- type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
454
- declare function WithErrorBoundaryProps({ children, }: {
455
- children: React.ReactElement;
456
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
457
- declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
458
- params: Readonly<Params<string>>;
459
- loaderData: any;
460
- actionData: any;
461
- error: unknown;
462
- }, string | React.JSXElementConstructor<any>>;
463
-
464
- type ParamKeyValuePair = [string, string];
465
- type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
466
- /**
467
- Creates a URLSearchParams object using the given initializer.
468
-
469
- This is identical to `new URLSearchParams(init)` except it also
470
- supports arrays as values in the object form of the initializer
471
- instead of just strings. This is convenient when you need multiple
472
- values for a given key, but don't want to use an array initializer.
473
-
474
- For example, instead of:
475
-
476
- ```tsx
477
- let searchParams = new URLSearchParams([
478
- ['sort', 'name'],
479
- ['sort', 'price']
480
- ]);
481
- ```
482
- you can do:
483
-
484
- ```
485
- let searchParams = createSearchParams({
486
- sort: ['name', 'price']
487
- });
488
- ```
489
-
490
- @category Utils
491
- */
492
- declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
493
- type JsonObject = {
494
- [Key in string]: JsonValue;
495
- } & {
496
- [Key in string]?: JsonValue | undefined;
497
- };
498
- type JsonArray = JsonValue[] | readonly JsonValue[];
499
- type JsonPrimitive = string | number | boolean | null;
500
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
501
- type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | JsonValue | null;
502
- /**
503
- * Submit options shared by both navigations and fetchers
504
- */
505
- interface SharedSubmitOptions {
506
- /**
507
- * The HTTP method used to submit the form. Overrides `<form method>`.
508
- * Defaults to "GET".
509
- */
510
- method?: HTMLFormMethod;
511
- /**
512
- * The action URL path used to submit the form. Overrides `<form action>`.
513
- * Defaults to the path of the current route.
514
- */
515
- action?: string;
516
- /**
517
- * The encoding used to submit the form. Overrides `<form encType>`.
518
- * Defaults to "application/x-www-form-urlencoded".
519
- */
520
- encType?: FormEncType;
521
- /**
522
- * Determines whether the form action is relative to the route hierarchy or
523
- * the pathname. Use this if you want to opt out of navigating the route
524
- * hierarchy and want to instead route based on /-delimited URL segments
525
- */
526
- relative?: RelativeRoutingType;
527
- /**
528
- * In browser-based environments, prevent resetting scroll after this
529
- * navigation when using the <ScrollRestoration> component
530
- */
531
- preventScrollReset?: boolean;
532
- /**
533
- * Enable flushSync for this submission's state updates
534
- */
535
- flushSync?: boolean;
536
- }
537
- /**
538
- * Submit options available to fetchers
539
- */
540
- interface FetcherSubmitOptions extends SharedSubmitOptions {
541
- }
542
- /**
543
- * Submit options available to navigations
544
- */
545
- interface SubmitOptions extends FetcherSubmitOptions {
546
- /**
547
- * Set `true` to replace the current entry in the browser's history stack
548
- * instead of creating a new one (i.e. stay on "the same page"). Defaults
549
- * to `false`.
550
- */
551
- replace?: boolean;
552
- /**
553
- * State object to add to the history stack entry for this navigation
554
- */
555
- state?: any;
556
- /**
557
- * Indicate a specific fetcherKey to use when using navigate=false
558
- */
559
- fetcherKey?: string;
560
- /**
561
- * navigate=false will use a fetcher instead of a navigation
562
- */
563
- navigate?: boolean;
564
- /**
565
- * Enable view transitions on this submission navigation
566
- */
567
- viewTransition?: boolean;
568
- }
569
-
570
- type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
571
- interface ServerRoute extends Route {
572
- children: ServerRoute[];
573
- module: ServerRouteModule;
574
- }
575
-
576
- type OptionalCriticalCss = CriticalCss | undefined;
577
- /**
578
- * The output of the compiler for the server build.
579
- */
580
- interface ServerBuild {
581
- entry: {
582
- module: ServerEntryModule;
583
- };
584
- routes: ServerRouteManifest;
585
- assets: AssetsManifest;
586
- basename?: string;
587
- publicPath: string;
588
- assetsBuildDirectory: string;
589
- future: FutureConfig;
590
- ssr: boolean;
591
- unstable_getCriticalCss?: (args: {
592
- pathname: string;
593
- }) => OptionalCriticalCss | Promise<OptionalCriticalCss>;
594
- /**
595
- * @deprecated This is now done via a custom header during prerendering
596
- */
597
- isSpaMode: boolean;
598
- prerender: string[];
599
- routeDiscovery: {
600
- mode: "lazy" | "initial";
601
- manifestPath: string;
602
- };
603
- }
604
- interface HandleDocumentRequestFunction {
605
- (request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: MiddlewareEnabled extends true ? unstable_RouterContextProvider : AppLoadContext): Promise<Response> | Response;
606
- }
607
- interface HandleDataRequestFunction {
608
- (response: Response, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<Response> | Response;
609
- }
610
- interface HandleErrorFunction {
611
- (error: unknown, args: LoaderFunctionArgs | ActionFunctionArgs): void;
612
- }
613
- /**
614
- * A module that serves as the entry point for a Remix app during server
615
- * rendering.
616
- */
617
- interface ServerEntryModule {
618
- default: HandleDocumentRequestFunction;
619
- handleDataRequest?: HandleDataRequestFunction;
620
- handleError?: HandleErrorFunction;
621
- streamTimeout?: number;
622
- }
623
-
624
- interface Route {
625
- index?: boolean;
626
- caseSensitive?: boolean;
627
- id: string;
628
- parentId?: string;
629
- path?: string;
630
- }
631
- interface EntryRoute extends Route {
632
- hasAction: boolean;
633
- hasLoader: boolean;
634
- hasClientAction: boolean;
635
- hasClientLoader: boolean;
636
- hasClientMiddleware: boolean;
637
- hasErrorBoundary: boolean;
638
- imports?: string[];
639
- css?: string[];
640
- module: string;
641
- clientActionModule: string | undefined;
642
- clientLoaderModule: string | undefined;
643
- clientMiddlewareModule: string | undefined;
644
- hydrateFallbackModule: string | undefined;
645
- parentId?: string;
646
- }
647
- declare function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation: Set<string>, manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState, ssr: boolean, isSpaMode: boolean): DataRouteObject[];
648
- declare function createClientRoutes(manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState | null, ssr: boolean, isSpaMode: boolean, parentId?: string, routesByParentId?: Record<string, Omit<EntryRoute, "children">[]>, needsRevalidation?: Set<string>): DataRouteObject[];
649
- declare function shouldHydrateRouteLoader(routeId: string, clientLoader: ClientLoaderFunction | undefined, hasLoader: boolean, isSpaMode: boolean): boolean;
650
-
651
- type SerializedError = {
652
- message: string;
653
- stack?: string;
654
- };
655
- interface FrameworkContextObject {
656
- manifest: AssetsManifest;
657
- routeModules: RouteModules;
658
- criticalCss?: CriticalCss;
659
- serverHandoffString?: string;
660
- future: FutureConfig;
661
- ssr: boolean;
662
- isSpaMode: boolean;
663
- routeDiscovery: ServerBuild["routeDiscovery"];
664
- serializeError?(error: Error): SerializedError;
665
- renderMeta?: {
666
- didRenderScripts?: boolean;
667
- streamCache?: Record<number, Promise<void> & {
668
- result?: {
669
- done: boolean;
670
- value: string;
671
- };
672
- error?: unknown;
673
- }>;
674
- };
675
- }
676
- interface EntryContext extends FrameworkContextObject {
677
- staticHandlerContext: StaticHandlerContext;
678
- serverHandoffStream?: ReadableStream<Uint8Array>;
679
- }
680
- interface FutureConfig {
681
- unstable_subResourceIntegrity: boolean;
682
- unstable_middleware: boolean;
683
- }
684
- type CriticalCss = string | {
685
- rel: "stylesheet";
686
- href: string;
687
- };
688
- interface AssetsManifest {
689
- entry: {
690
- imports: string[];
691
- module: string;
692
- };
693
- routes: RouteManifest<EntryRoute>;
694
- url: string;
695
- version: string;
696
- hmr?: {
697
- timestamp?: number;
698
- runtime: string;
699
- };
700
- sri?: Record<string, string> | true;
701
- }
702
-
703
- declare const FrameworkContext: React.Context<FrameworkContextObject | undefined>;
704
- /**
705
- * Defines the discovery behavior of the link:
706
- *
707
- * - "render" - default, discover the route when the link renders
708
- * - "none" - don't eagerly discover, only discover if the link is clicked
709
- */
710
- type DiscoverBehavior = "render" | "none";
711
- /**
712
- * Defines the prefetching behavior of the link:
713
- *
714
- * - "none": Never fetched
715
- * - "intent": Fetched when the user focuses or hovers the link
716
- * - "render": Fetched when the link is rendered
717
- * - "viewport": Fetched when the link is in the viewport
718
- */
719
- type PrefetchBehavior = "intent" | "render" | "none" | "viewport";
720
- /**
721
- Renders all of the `<link>` tags created by route module {@link LinksFunction} export. You should render it inside the `<head>` of your document.
722
-
723
- ```tsx
724
- import { Links } from "react-router";
725
-
726
- export default function Root() {
727
- return (
728
- <html>
729
- <head>
730
- <Links />
731
- </head>
732
- <body></body>
733
- </html>
734
- );
735
- }
736
- ```
737
-
738
- @category Components
739
- */
740
- declare function Links(): React.JSX.Element;
741
- /**
742
- Renders `<link rel=prefetch|modulepreload>` tags for modules and data of another page to enable an instant navigation to that page. {@link LinkProps.prefetch | `<Link prefetch>`} uses this internally, but you can render it to prefetch a page for any other reason.
743
-
744
- ```tsx
745
- import { PrefetchPageLinks } from "react-router"
746
-
747
- <PrefetchPageLinks page="/absolute/path" />
748
- ```
749
-
750
- For example, you may render one of this as the user types into a search field to prefetch search results before they click through to their selection.
751
-
752
- @category Components
753
- */
754
- declare function PrefetchPageLinks({ page, ...dataLinkProps }: PageLinkDescriptor): React.JSX.Element | null;
755
- /**
756
- Renders all the `<meta>` tags created by route module {@link MetaFunction} exports. You should render it inside the `<head>` of your HTML.
757
-
758
- ```tsx
759
- import { Meta } from "react-router";
760
-
761
- export default function Root() {
762
- return (
763
- <html>
764
- <head>
765
- <Meta />
766
- </head>
767
- </html>
768
- );
769
- }
770
- ```
771
-
772
- @category Components
773
- */
774
- declare function Meta(): React.JSX.Element;
775
- /**
776
- A couple common attributes:
777
-
778
- - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
779
- - `<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.
780
-
781
- You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
782
-
783
- @category Types
784
- */
785
- type ScriptsProps = Omit<React.HTMLProps<HTMLScriptElement>, "children" | "async" | "defer" | "src" | "type" | "noModule" | "dangerouslySetInnerHTML" | "suppressHydrationWarning">;
786
- /**
787
- Renders the client runtime of your app. It should be rendered inside the `<body>` of the document.
788
-
789
- ```tsx
790
- import { Scripts } from "react-router";
791
-
792
- export default function Root() {
793
- return (
794
- <html>
795
- <head />
796
- <body>
797
- <Scripts />
798
- </body>
799
- </html>
800
- );
801
- }
802
- ```
803
-
804
- If server rendering, you can omit `<Scripts/>` and the app will work as a traditional web app without JavaScript, relying solely on HTML and browser behaviors.
805
-
806
- @category Components
807
- */
808
- declare function Scripts(props: ScriptsProps): React.JSX.Element | null;
809
-
810
- /**
811
- * @category Routers
812
- */
813
- interface DOMRouterOpts {
814
- /**
815
- * Basename path for the application.
816
- */
817
- basename?: string;
818
- /**
819
- * Function to provide the initial context values for all client side navigations/fetches
820
- */
821
- unstable_getContext?: RouterInit["unstable_getContext"];
822
- /**
823
- * Future flags to enable for the router.
824
- */
825
- future?: Partial<FutureConfig$1>;
826
- /**
827
- * Hydration data to initialize the router with if you have already performed
828
- * data loading on the server.
829
- */
830
- hydrationData?: HydrationState;
831
- /**
832
- * Override the default data strategy of loading in parallel.
833
- * Only intended for advanced usage.
834
- */
835
- dataStrategy?: DataStrategyFunction;
836
- /**
837
- * Lazily define portions of the route tree on navigations.
838
- */
839
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
840
- /**
841
- * Window object override - defaults to the global `window` instance.
842
- */
843
- window?: Window;
844
- }
845
- /**
846
- * Create a new data router that manages the application path via `history.pushState`
847
- * and `history.replaceState`.
848
- *
849
- * @category Data Routers
850
- */
851
- declare function createBrowserRouter(
852
- /**
853
- * Application routes
854
- */
855
- routes: RouteObject[],
856
- /**
857
- * Router options
858
- */
859
- opts?: DOMRouterOpts): Router$1;
860
- /**
861
- * Create a new data router that manages the application path via the URL hash
862
- *
863
- * @category Data Routers
864
- */
865
- declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router$1;
866
- /**
867
- * @category Types
868
- */
869
- interface BrowserRouterProps {
870
- basename?: string;
871
- children?: React.ReactNode;
872
- window?: Window;
873
- }
874
- /**
875
- * A `<Router>` for use in web browsers. Provides the cleanest URLs.
876
- *
877
- * @category Component Routers
878
- */
879
- declare function BrowserRouter({ basename, children, window, }: BrowserRouterProps): React.JSX.Element;
880
- /**
881
- * @category Types
882
- */
883
- interface HashRouterProps {
884
- basename?: string;
885
- children?: React.ReactNode;
886
- window?: Window;
887
- }
888
- /**
889
- * A `<Router>` for use in web browsers. Stores the location in the hash
890
- * portion of the URL so it is not sent to the server.
891
- *
892
- * @category Component Routers
893
- */
894
- declare function HashRouter({ basename, children, window }: HashRouterProps): React.JSX.Element;
895
- /**
896
- * @category Types
897
- */
898
- interface HistoryRouterProps {
899
- basename?: string;
900
- children?: React.ReactNode;
901
- history: History;
902
- }
903
- /**
904
- * A `<Router>` that accepts a pre-instantiated history object. It's important
905
- * to note that using your own history object is highly discouraged and may add
906
- * two versions of the history library to your bundles unless you use the same
907
- * version of the history library that React Router uses internally.
908
- *
909
- * @name unstable_HistoryRouter
910
- * @category Component Routers
911
- */
912
- declare function HistoryRouter({ basename, children, history, }: HistoryRouterProps): React.JSX.Element;
913
- declare namespace HistoryRouter {
914
- var displayName: string;
915
- }
916
- /**
917
- * @category Types
918
- */
919
- interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
920
- /**
921
- Defines the link discovery behavior
922
-
923
- ```tsx
924
- <Link /> // default ("render")
925
- <Link discover="render" />
926
- <Link discover="none" />
927
- ```
928
-
929
- - **render** - default, discover the route when the link renders
930
- - **none** - don't eagerly discover, only discover if the link is clicked
931
- */
932
- discover?: DiscoverBehavior;
933
- /**
934
- Defines the data and module prefetching behavior for the link.
935
-
936
- ```tsx
937
- <Link /> // default
938
- <Link prefetch="none" />
939
- <Link prefetch="intent" />
940
- <Link prefetch="render" />
941
- <Link prefetch="viewport" />
942
- ```
943
-
944
- - **none** - default, no prefetching
945
- - **intent** - prefetches when the user hovers or focuses the link
946
- - **render** - prefetches when the link renders
947
- - **viewport** - prefetches when the link is in the viewport, very useful for mobile
948
-
949
- Prefetching is done with HTML `<link rel="prefetch">` tags. They are inserted after the link.
950
-
951
- ```tsx
952
- <a href="..." />
953
- <a href="..." />
954
- <link rel="prefetch" /> // might conditionally render
955
- ```
956
-
957
- Because of this, if you are using `nav :last-child` you will need to use `nav :last-of-type` so the styles don't conditionally fall off your last link (and any other similar selectors).
958
- */
959
- prefetch?: PrefetchBehavior;
960
- /**
961
- Will use document navigation instead of client side routing when the link is clicked: the browser will handle the transition normally (as if it were an `<a href>`).
962
-
963
- ```tsx
964
- <Link to="/logout" reloadDocument />
965
- ```
966
- */
967
- reloadDocument?: boolean;
968
- /**
969
- Replaces the current entry in the history stack instead of pushing a new one onto it.
970
-
971
- ```tsx
972
- <Link replace />
973
- ```
974
-
975
- ```
976
- # with a history stack like this
977
- A -> B
978
-
979
- # normal link click pushes a new entry
980
- A -> B -> C
981
-
982
- # but with `replace`, B is replaced by C
983
- A -> C
984
- ```
985
- */
986
- replace?: boolean;
987
- /**
988
- Adds persistent client side routing state to the next location.
989
-
990
- ```tsx
991
- <Link to="/somewhere/else" state={{ some: "value" }} />
992
- ```
993
-
994
- The location state is accessed from the `location`.
995
-
996
- ```tsx
997
- function SomeComp() {
998
- const location = useLocation()
999
- location.state; // { some: "value" }
1000
- }
1001
- ```
1002
-
1003
- This state is inaccessible on the server as it is implemented on top of [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state)
1004
- */
1005
- state?: any;
1006
- /**
1007
- Prevents the scroll position from being reset to the top of the window when the link is clicked and the app is using {@link ScrollRestoration}. This only prevents new locations reseting scroll to the top, scroll position will be restored for back/forward button navigation.
1008
-
1009
- ```tsx
1010
- <Link to="?tab=one" preventScrollReset />
1011
- ```
1012
- */
1013
- preventScrollReset?: boolean;
1014
- /**
1015
- Defines the relative path behavior for the link.
1016
-
1017
- ```tsx
1018
- <Link to=".." /> // default: "route"
1019
- <Link relative="route" />
1020
- <Link relative="path" />
1021
- ```
1022
-
1023
- Consider a route hierarchy where a parent route pattern is "blog" and a child route pattern is "blog/:slug/edit".
1024
-
1025
- - **route** - default, resolves the link relative to the route pattern. In the example above a relative link of `".."` will remove both `:slug/edit` segments back to "/blog".
1026
- - **path** - relative to the path so `..` will only remove one URL segment up to "/blog/:slug"
1027
- */
1028
- relative?: RelativeRoutingType;
1029
- /**
1030
- Can be a string or a partial {@link Path}:
1031
-
1032
- ```tsx
1033
- <Link to="/some/path" />
1034
-
1035
- <Link
1036
- to={{
1037
- pathname: "/some/path",
1038
- search: "?query=string",
1039
- hash: "#hash",
1040
- }}
1041
- />
1042
- ```
1043
- */
1044
- to: To;
1045
- /**
1046
- Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) for this navigation.
1047
-
1048
- ```jsx
1049
- <Link to={to} viewTransition>
1050
- Click me
1051
- </Link>
1052
- ```
1053
-
1054
- To apply specific styles for the transition, see {@link useViewTransitionState}
1055
- */
1056
- viewTransition?: boolean;
1057
- }
1058
- /**
1059
- A progressively enhanced `<a href>` wrapper to enable navigation with client-side routing.
1060
-
1061
- ```tsx
1062
- import { Link } from "react-router";
1063
-
1064
- <Link to="/dashboard">Dashboard</Link>;
1065
-
1066
- <Link
1067
- to={{
1068
- pathname: "/some/path",
1069
- search: "?query=string",
1070
- hash: "#hash",
1071
- }}
1072
- />
1073
- ```
1074
-
1075
- @category Components
1076
- */
1077
- declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
1078
- /**
1079
- The object passed to {@link NavLink} `children`, `className`, and `style` prop callbacks to render and style the link based on its state.
1080
-
1081
- ```
1082
- // className
1083
- <NavLink
1084
- to="/messages"
1085
- className={({ isActive, isPending }) =>
1086
- isPending ? "pending" : isActive ? "active" : ""
1087
- }
1088
- >
1089
- Messages
1090
- </NavLink>
1091
-
1092
- // style
1093
- <NavLink
1094
- to="/messages"
1095
- style={({ isActive, isPending }) => {
1096
- return {
1097
- fontWeight: isActive ? "bold" : "",
1098
- color: isPending ? "red" : "black",
1099
- }
1100
- )}
1101
- />
1102
-
1103
- // children
1104
- <NavLink to="/tasks">
1105
- {({ isActive, isPending }) => (
1106
- <span className={isActive ? "active" : ""}>Tasks</span>
1107
- )}
1108
- </NavLink>
1109
- ```
1110
-
1111
- */
1112
- type NavLinkRenderProps = {
1113
- /**
1114
- * Indicates if the link's URL matches the current location.
1115
- */
1116
- isActive: boolean;
1117
- /**
1118
- * Indicates if the pending location matches the link's URL.
1119
- */
1120
- isPending: boolean;
1121
- /**
1122
- * Indicates if a view transition to the link's URL is in progress. See {@link useViewTransitionState}
1123
- */
1124
- isTransitioning: boolean;
1125
- };
1126
- /**
1127
- * @category Types
1128
- */
1129
- interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
1130
- /**
1131
- Can be regular React children or a function that receives an object with the active and pending states of the link.
1132
-
1133
- ```tsx
1134
- <NavLink to="/tasks">
1135
- {({ isActive }) => (
1136
- <span className={isActive ? "active" : ""}>Tasks</span>
1137
- )}
1138
- </NavLink>
1139
- ```
1140
- */
1141
- children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode);
1142
- /**
1143
- Changes the matching logic to make it case-sensitive:
1144
-
1145
- | Link | URL | isActive |
1146
- | -------------------------------------------- | ------------- | -------- |
1147
- | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
1148
- | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
1149
- */
1150
- caseSensitive?: boolean;
1151
- /**
1152
- Classes are automatically applied to NavLink that correspond to {@link NavLinkRenderProps}.
1153
-
1154
- ```css
1155
- a.active { color: red; }
1156
- a.pending { color: blue; }
1157
- a.transitioning {
1158
- view-transition-name: my-transition;
1159
- }
1160
- ```
1161
- */
1162
- className?: string | ((props: NavLinkRenderProps) => string | undefined);
1163
- /**
1164
- Changes the matching logic for the `active` and `pending` states to only match to the "end" of the {@link NavLinkProps.to}. If the URL is longer, it will no longer be considered active.
1165
-
1166
- | Link | URL | isActive |
1167
- | ----------------------------- | ------------ | -------- |
1168
- | `<NavLink to="/tasks" />` | `/tasks` | true |
1169
- | `<NavLink to="/tasks" />` | `/tasks/123` | true |
1170
- | `<NavLink to="/tasks" end />` | `/tasks` | true |
1171
- | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
1172
-
1173
- `<NavLink to="/">` is an exceptional case because _every_ URL matches `/`. To avoid this matching every single route by default, it effectively ignores the `end` prop and only matches when you're at the root route.
1174
- */
1175
- end?: boolean;
1176
- style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined);
1177
- }
1178
- /**
1179
- Wraps {@link Link | `<Link>`} with additional props for styling active and pending states.
1180
-
1181
- - Automatically applies classes to the link based on its active and pending states, see {@link NavLinkProps.className}.
1182
- - Automatically applies `aria-current="page"` to the link when the link is active. See [`aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current) on MDN.
1183
-
1184
- ```tsx
1185
- import { NavLink } from "react-router"
1186
- <NavLink to="/message" />
1187
- ```
1188
-
1189
- States are available through the className, style, and children render props. See {@link NavLinkRenderProps}.
1190
-
1191
- ```tsx
1192
- <NavLink
1193
- to="/messages"
1194
- className={({ isActive, isPending }) =>
1195
- isPending ? "pending" : isActive ? "active" : ""
1196
- }
1197
- >
1198
- Messages
1199
- </NavLink>
1200
- ```
1201
-
1202
- @category Components
1203
- */
1204
- declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
1205
- /**
1206
- * Form props shared by navigations and fetchers
1207
- */
1208
- interface SharedFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
1209
- /**
1210
- * The HTTP verb to use when the form is submitted. Supports "get", "post",
1211
- * "put", "delete", and "patch".
1212
- *
1213
- * Native `<form>` only supports `get` and `post`, avoid the other verbs if
1214
- * you'd like to support progressive enhancement
1215
- */
1216
- method?: HTMLFormMethod;
1217
- /**
1218
- * The encoding type to use for the form submission.
1219
- */
1220
- encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
1221
- /**
1222
- * The URL to submit the form data to. If `undefined`, this defaults to the closest route in context.
1223
- */
1224
- action?: string;
1225
- /**
1226
- * Determines whether the form action is relative to the route hierarchy or
1227
- * the pathname. Use this if you want to opt out of navigating the route
1228
- * hierarchy and want to instead route based on /-delimited URL segments
1229
- */
1230
- relative?: RelativeRoutingType;
1231
- /**
1232
- * Prevent the scroll position from resetting to the top of the viewport on
1233
- * completion of the navigation when using the <ScrollRestoration> component
1234
- */
1235
- preventScrollReset?: boolean;
1236
- /**
1237
- * A function to call when the form is submitted. If you call
1238
- * `event.preventDefault()` then this form will not do anything.
1239
- */
1240
- onSubmit?: React.FormEventHandler<HTMLFormElement>;
1241
- }
1242
- /**
1243
- * Form props available to fetchers
1244
- * @category Types
1245
- */
1246
- interface FetcherFormProps extends SharedFormProps {
1247
- }
1248
- /**
1249
- * Form props available to navigations
1250
- * @category Types
1251
- */
1252
- interface FormProps extends SharedFormProps {
1253
- discover?: DiscoverBehavior;
1254
- /**
1255
- * Indicates a specific fetcherKey to use when using `navigate={false}` so you
1256
- * can pick up the fetcher's state in a different component in a {@link
1257
- * useFetcher}.
1258
- */
1259
- fetcherKey?: string;
1260
- /**
1261
- * Skips the navigation and uses a {@link useFetcher | fetcher} internally
1262
- * when `false`. This is essentially a shorthand for `useFetcher()` +
1263
- * `<fetcher.Form>` where you don't care about the resulting data in this
1264
- * component.
1265
- */
1266
- navigate?: boolean;
1267
- /**
1268
- * Forces a full document navigation instead of client side routing + data
1269
- * fetch.
1270
- */
1271
- reloadDocument?: boolean;
1272
- /**
1273
- * Replaces the current entry in the browser history stack when the form
1274
- * navigates. Use this if you don't want the user to be able to click "back"
1275
- * to the page with the form on it.
1276
- */
1277
- replace?: boolean;
1278
- /**
1279
- * State object to add to the history stack entry for this navigation
1280
- */
1281
- state?: any;
1282
- /**
1283
- * Enables a [View
1284
- * Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
1285
- * for this navigation. To apply specific styles during the transition see
1286
- * {@link useViewTransitionState}.
1287
- */
1288
- viewTransition?: boolean;
1289
- }
1290
- /**
1291
-
1292
- A progressively enhanced HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) that submits data to actions via `fetch`, activating pending states in `useNavigation` which enables advanced user interfaces beyond a basic HTML form. After a form's action completes, all data on the page is automatically revalidated to keep the UI in sync with the data.
1293
-
1294
- Because it uses the HTML form API, server rendered pages are interactive at a basic level before JavaScript loads. Instead of React Router managing the submission, the browser manages the submission as well as the pending states (like the spinning favicon). After JavaScript loads, React Router takes over enabling web application user experiences.
1295
-
1296
- Form is most useful for submissions that should also change the URL or otherwise add an entry to the browser history stack. For forms that shouldn't manipulate the browser history stack, use [`<fetcher.Form>`][fetcher_form].
1297
-
1298
- ```tsx
1299
- import { Form } from "react-router";
1300
-
1301
- function NewEvent() {
1302
- return (
1303
- <Form action="/events" method="post">
1304
- <input name="title" type="text" />
1305
- <input name="description" type="text" />
1306
- </Form>
1307
- )
1308
- }
1309
- ```
1310
-
1311
- @category Components
1312
- */
1313
- declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
1314
- type ScrollRestorationProps = ScriptsProps & {
1315
- /**
1316
- Defines the key used to restore scroll positions.
1317
-
1318
- ```tsx
1319
- <ScrollRestoration
1320
- getKey={(location, matches) => {
1321
- // default behavior
1322
- return location.key
1323
- }}
1324
- />
1325
- ```
1326
- */
1327
- getKey?: GetScrollRestorationKeyFunction;
1328
- storageKey?: string;
1329
- };
1330
- /**
1331
- Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
1332
-
1333
- ```tsx
1334
- import { ScrollRestoration } from "react-router";
1335
-
1336
- export default function Root() {
1337
- return (
1338
- <html>
1339
- <body>
1340
- <ScrollRestoration />
1341
- <Scripts />
1342
- </body>
1343
- </html>
1344
- );
1345
- }
1346
- ```
1347
-
1348
- This component renders an inline `<script>` to prevent scroll flashing. The `nonce` prop will be passed down to the script tag to allow CSP nonce usage.
1349
-
1350
- ```tsx
1351
- <ScrollRestoration nonce={cspNonce} />
1352
- ```
1353
-
1354
- @category Components
1355
- */
1356
- declare function ScrollRestoration({ getKey, storageKey, ...props }: ScrollRestorationProps): React.JSX.Element | null;
1357
- declare namespace ScrollRestoration {
1358
- var displayName: string;
1359
- }
1360
- /**
1361
- * Handles the click behavior for router `<Link>` components. This is useful if
1362
- * you need to create custom `<Link>` components with the same click behavior we
1363
- * use in our exported `<Link>`.
1364
- *
1365
- * @category Hooks
1366
- */
1367
- declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, viewTransition, }?: {
1368
- target?: React.HTMLAttributeAnchorTarget;
1369
- replace?: boolean;
1370
- state?: any;
1371
- preventScrollReset?: boolean;
1372
- relative?: RelativeRoutingType;
1373
- viewTransition?: boolean;
1374
- }): (event: React.MouseEvent<E, MouseEvent>) => void;
1375
- /**
1376
- Returns a tuple of the current URL's {@link URLSearchParams} and a function to update them. Setting the search params causes a navigation.
1377
-
1378
- ```tsx
1379
- import { useSearchParams } from "react-router";
1380
-
1381
- export function SomeComponent() {
1382
- const [searchParams, setSearchParams] = useSearchParams();
1383
- // ...
1384
- }
1385
- ```
1386
-
1387
- @category Hooks
1388
- */
1389
- declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
1390
- /**
1391
- Sets new search params and causes a navigation when called.
1392
-
1393
- ```tsx
1394
- <button
1395
- onClick={() => {
1396
- const params = new URLSearchParams();
1397
- params.set("someKey", "someValue");
1398
- setSearchParams(params, {
1399
- preventScrollReset: true,
1400
- });
1401
- }}
1402
- />
1403
- ```
1404
-
1405
- It also supports a function for setting new search params.
1406
-
1407
- ```tsx
1408
- <button
1409
- onClick={() => {
1410
- setSearchParams((prev) => {
1411
- prev.set("someKey", "someValue");
1412
- return prev;
1413
- });
1414
- }}
1415
- />
1416
- ```
1417
- */
1418
- type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
1419
- /**
1420
- * Submits a HTML `<form>` to the server without reloading the page.
1421
- */
1422
- interface SubmitFunction {
1423
- (
1424
- /**
1425
- Can be multiple types of elements and objects
1426
-
1427
- **`HTMLFormElement`**
1428
-
1429
- ```tsx
1430
- <Form
1431
- onSubmit={(event) => {
1432
- submit(event.currentTarget);
1433
- }}
1434
- />
1435
- ```
1436
-
1437
- **`FormData`**
1438
-
1439
- ```tsx
1440
- const formData = new FormData();
1441
- formData.append("myKey", "myValue");
1442
- submit(formData, { method: "post" });
1443
- ```
1444
-
1445
- **Plain object that will be serialized as `FormData`**
1446
-
1447
- ```tsx
1448
- submit({ myKey: "myValue" }, { method: "post" });
1449
- ```
1450
-
1451
- **Plain object that will be serialized as JSON**
1452
-
1453
- ```tsx
1454
- submit(
1455
- { myKey: "myValue" },
1456
- { method: "post", encType: "application/json" }
1457
- );
1458
- ```
1459
- */
1460
- target: SubmitTarget,
1461
- /**
1462
- * Options that override the `<form>`'s own attributes. Required when
1463
- * submitting arbitrary data without a backing `<form>`.
1464
- */
1465
- options?: SubmitOptions): Promise<void>;
1466
- }
1467
- /**
1468
- * Submits a fetcher `<form>` to the server without reloading the page.
1469
- */
1470
- interface FetcherSubmitFunction {
1471
- (
1472
- /**
1473
- Can be multiple types of elements and objects
1474
-
1475
- **`HTMLFormElement`**
1476
-
1477
- ```tsx
1478
- <fetcher.Form
1479
- onSubmit={(event) => {
1480
- fetcher.submit(event.currentTarget);
1481
- }}
1482
- />
1483
- ```
1484
-
1485
- **`FormData`**
1486
-
1487
- ```tsx
1488
- const formData = new FormData();
1489
- formData.append("myKey", "myValue");
1490
- fetcher.submit(formData, { method: "post" });
1491
- ```
1492
-
1493
- **Plain object that will be serialized as `FormData`**
1494
-
1495
- ```tsx
1496
- fetcher.submit({ myKey: "myValue" }, { method: "post" });
1497
- ```
1498
-
1499
- **Plain object that will be serialized as JSON**
1500
-
1501
- ```tsx
1502
- fetcher.submit(
1503
- { myKey: "myValue" },
1504
- { method: "post", encType: "application/json" }
1505
- );
1506
- ```
1507
-
1508
- */
1509
- target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
1510
- }
1511
- /**
1512
- The imperative version of {@link Form | `<Form>`} that lets you submit a form from code instead of a user interaction.
1513
-
1514
- ```tsx
1515
- import { useSubmit } from "react-router";
1516
-
1517
- function SomeComponent() {
1518
- const submit = useSubmit();
1519
- return (
1520
- <Form
1521
- onChange={(event) => {
1522
- submit(event.currentTarget);
1523
- }}
1524
- />
1525
- );
1526
- }
1527
- ```
1528
-
1529
- @category Hooks
1530
- */
1531
- declare function useSubmit(): SubmitFunction;
1532
- /**
1533
- Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.
1534
-
1535
- This is used internally by {@link Form} resolve the action to the closest route, but can be used generically as well.
1536
-
1537
- ```tsx
1538
- import { useFormAction } from "react-router";
1539
-
1540
- function SomeComponent() {
1541
- // closest route URL
1542
- let action = useFormAction();
1543
-
1544
- // closest route URL + "destroy"
1545
- let destroyAction = useFormAction("destroy");
1546
- }
1547
- ```
1548
-
1549
- @category Hooks
1550
- */
1551
- declare function useFormAction(
1552
- /**
1553
- * The action to append to the closest route URL.
1554
- */
1555
- action?: string, { relative }?: {
1556
- relative?: RelativeRoutingType;
1557
- }): string;
1558
- /**
1559
- The return value of `useFetcher` that keeps track of the state of a fetcher.
1560
-
1561
- ```tsx
1562
- let fetcher = useFetcher();
1563
- ```
1564
- */
1565
- type FetcherWithComponents<TData> = Fetcher<TData> & {
1566
- /**
1567
- Just like {@link Form} except it doesn't cause a navigation.
1568
-
1569
- ```tsx
1570
- function SomeComponent() {
1571
- const fetcher = useFetcher()
1572
- return (
1573
- <fetcher.Form method="post" action="/some/route">
1574
- <input type="text" />
1575
- </fetcher.Form>
1576
- )
1577
- }
1578
- ```
1579
- */
1580
- Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
1581
- /**
1582
- Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
1583
-
1584
- The `formData` can be multiple types:
1585
-
1586
- - [`FormData`][form_data] - A `FormData` instance.
1587
- - [`HTMLFormElement`][html_form_element] - A [`<form>`][form_element] DOM element.
1588
- - `Object` - An object of key/value pairs that will be converted to a `FormData` instance by default. You can pass a more complex object and serialize it as JSON by specifying `encType: "application/json"`. See [`useSubmit`][use-submit] for more details.
1589
-
1590
- If the method is `GET`, then the route [`loader`][loader] is being called and with the `formData` serialized to the url as [`URLSearchParams`][url_search_params]. If `DELETE`, `PATCH`, `POST`, or `PUT`, then the route [`action`][action] is being called with `formData` as the body.
1591
-
1592
- ```tsx
1593
- // Submit a FormData instance (GET request)
1594
- const formData = new FormData();
1595
- fetcher.submit(formData);
1596
-
1597
- // Submit the HTML form element
1598
- fetcher.submit(event.currentTarget.form, {
1599
- method: "POST",
1600
- });
1601
-
1602
- // Submit key/value JSON as a FormData instance
1603
- fetcher.submit(
1604
- { serialized: "values" },
1605
- { method: "POST" }
1606
- );
1607
-
1608
- // Submit raw JSON
1609
- fetcher.submit(
1610
- {
1611
- deeply: {
1612
- nested: {
1613
- json: "values",
1614
- },
1615
- },
1616
- },
1617
- {
1618
- method: "POST",
1619
- encType: "application/json",
1620
- }
1621
- );
1622
- ```
1623
- */
1624
- submit: FetcherSubmitFunction;
1625
- /**
1626
- Loads data from a route. Useful for loading data imperatively inside of user events outside of a normal button or form, like a combobox or search input.
1627
-
1628
- ```tsx
1629
- let fetcher = useFetcher()
1630
-
1631
- <input onChange={e => {
1632
- fetcher.load(`/search?q=${e.target.value}`)
1633
- }} />
1634
- ```
1635
- */
1636
- load: (href: string, opts?: {
1637
- /**
1638
- * Wraps the initial state update for this `fetcher.load` in a
1639
- * `ReactDOM.flushSync` call instead of the default `React.startTransition`.
1640
- * This allows you to perform synchronous DOM actions immediately after the
1641
- * update is flushed to the DOM.
1642
- */
1643
- flushSync?: boolean;
1644
- }) => Promise<void>;
1645
- };
1646
- /**
1647
- Useful for creating complex, dynamic user interfaces that require multiple, concurrent data interactions without causing a navigation.
1648
-
1649
- Fetchers track their own, independent state and can be used to load data, submit forms, and generally interact with loaders and actions.
1650
-
1651
- ```tsx
1652
- import { useFetcher } from "react-router"
1653
-
1654
- function SomeComponent() {
1655
- let fetcher = useFetcher()
1656
-
1657
- // states are available on the fetcher
1658
- fetcher.state // "idle" | "loading" | "submitting"
1659
- fetcher.data // the data returned from the action or loader
1660
-
1661
- // render a form
1662
- <fetcher.Form method="post" />
1663
-
1664
- // load data
1665
- fetcher.load("/some/route")
1666
-
1667
- // submit data
1668
- fetcher.submit(someFormRef, { method: "post" })
1669
- fetcher.submit(someData, {
1670
- method: "post",
1671
- encType: "application/json"
1672
- })
1673
- }
1674
- ```
1675
-
1676
- @category Hooks
1677
- */
1678
- declare function useFetcher<T = any>({ key, }?: {
1679
- /**
1680
- By default, `useFetcher` generate a unique fetcher scoped to that component. If you want to identify a fetcher with your own key such that you can access it from elsewhere in your app, you can do that with the `key` option:
1681
-
1682
- ```tsx
1683
- function SomeComp() {
1684
- let fetcher = useFetcher({ key: "my-key" })
1685
- // ...
1686
- }
1687
-
1688
- // Somewhere else
1689
- function AnotherComp() {
1690
- // this will be the same fetcher, sharing the state across the app
1691
- let fetcher = useFetcher({ key: "my-key" });
1692
- // ...
1693
- }
1694
- ```
1695
- */
1696
- key?: string;
1697
- }): FetcherWithComponents<SerializeFrom<T>>;
1698
- /**
1699
- Returns an array of all in-flight fetchers. This is useful for components throughout the app that didn't create the fetchers but want to use their submissions to participate in optimistic UI.
1700
-
1701
- ```tsx
1702
- import { useFetchers } from "react-router";
1703
-
1704
- function SomeComponent() {
1705
- const fetchers = useFetchers();
1706
- fetchers[0].formData; // FormData
1707
- fetchers[0].state; // etc.
1708
- // ...
1709
- }
1710
- ```
1711
-
1712
- @category Hooks
1713
- */
1714
- declare function useFetchers(): (Fetcher & {
1715
- key: string;
1716
- })[];
1717
- /**
1718
- * When rendered inside a RouterProvider, will restore scroll positions on navigations
1719
- */
1720
- declare function useScrollRestoration({ getKey, storageKey, }?: {
1721
- getKey?: GetScrollRestorationKeyFunction;
1722
- storageKey?: string;
1723
- }): void;
1724
- /**
1725
- * Setup a callback to be fired on the window's `beforeunload` event.
1726
- *
1727
- * @category Hooks
1728
- */
1729
- declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
1730
- capture?: boolean;
1731
- }): void;
1732
- /**
1733
- Wrapper around useBlocker to show a window.confirm prompt to users instead of building a custom UI with {@link useBlocker}.
1734
-
1735
- The `unstable_` flag will not be removed because this technique has a lot of rough edges and behaves very differently (and incorrectly sometimes) across browsers if users click addition back/forward navigations while the confirmation is open. Use at your own risk.
1736
-
1737
- ```tsx
1738
- function ImportantForm() {
1739
- let [value, setValue] = React.useState("");
1740
-
1741
- // Block navigating elsewhere when data has been entered into the input
1742
- unstable_usePrompt({
1743
- message: "Are you sure?",
1744
- when: ({ currentLocation, nextLocation }) =>
1745
- value !== "" &&
1746
- currentLocation.pathname !== nextLocation.pathname,
1747
- });
1748
-
1749
- return (
1750
- <Form method="post">
1751
- <label>
1752
- Enter some important data:
1753
- <input
1754
- name="data"
1755
- value={value}
1756
- onChange={(e) => setValue(e.target.value)}
1757
- />
1758
- </label>
1759
- <button type="submit">Save</button>
1760
- </Form>
1761
- );
1762
- }
1763
- ```
1764
-
1765
- @category Hooks
1766
- @name unstable_usePrompt
1767
- */
1768
- declare function usePrompt({ when, message, }: {
1769
- when: boolean | BlockerFunction;
1770
- message: string;
1771
- }): void;
1772
- /**
1773
- This hook returns `true` when there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition. This requires that view transitions have been enabled for the given navigation via {@link LinkProps.viewTransition} (or the `Form`, `submit`, or `navigate` call)
1774
-
1775
- @category Hooks
1776
- @name useViewTransitionState
1777
- */
1778
- declare function useViewTransitionState(to: To, opts?: {
1779
- relative?: RelativeRoutingType;
1780
- }): boolean;
1781
-
1782
- interface StaticRouterProps {
1783
- basename?: string;
1784
- children?: React.ReactNode;
1785
- location: Partial<Location> | string;
1786
- }
1787
- /**
1788
- * A `<Router>` that may not navigate to any other location. This is useful
1789
- * on the server where there is no stateful UI.
1790
- *
1791
- * @category Component Routers
1792
- */
1793
- declare function StaticRouter({ basename, children, location: locationProp, }: StaticRouterProps): React.JSX.Element;
1794
- interface StaticRouterProviderProps {
1795
- context: StaticHandlerContext;
1796
- router: Router$1;
1797
- hydrate?: boolean;
1798
- nonce?: string;
1799
- }
1800
- /**
1801
- * A Data Router that may not navigate to any other location. This is useful
1802
- * on the server where there is no stateful UI.
1803
- *
1804
- * @category Component Routers
1805
- */
1806
- declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): React.JSX.Element;
1807
- type CreateStaticHandlerOptions = Omit<CreateStaticHandlerOptions$1, "mapRouteProperties">;
1808
- /**
1809
- * @category Utils
1810
- */
1811
- declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1812
- /**
1813
- * @category Data Routers
1814
- */
1815
- declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
1816
- future?: Partial<FutureConfig$1>;
1817
- }): Router$1;
1818
-
1819
- export { ScrollRestoration as $, type AssetsManifest as A, type BrowserRouterProps as B, type ScrollRestorationProps as C, type DOMRouterOpts as D, type EntryContext as E, type FutureConfig as F, type SetURLSearchParams as G, type HydrateFallbackType as H, type IndexRouteProps as I, type SubmitFunction as J, type FetcherSubmitFunction as K, type LayoutRouteProps as L, type MemoryRouterOpts as M, type NavigateProps as N, type OutletProps as O, type PathRouteProps as P, type FetcherWithComponents as Q, type RouteComponentType as R, type ServerBuild as S, createBrowserRouter as T, createHashRouter as U, BrowserRouter as V, HashRouter as W, Link as X, HistoryRouter as Y, NavLink as Z, Form as _, type ErrorBoundaryType as a, useLinkClickHandler as a0, useSearchParams as a1, useSubmit as a2, useFormAction as a3, useFetcher as a4, useFetchers as a5, useBeforeUnload as a6, usePrompt as a7, useViewTransitionState as a8, type FetcherSubmitOptions as a9, WithErrorBoundaryProps as aA, withErrorBoundaryProps as aB, FrameworkContext as aC, createClientRoutes as aD, createClientRoutesWithHMRRevalidationOptOut as aE, shouldHydrateRouteLoader as aF, useScrollRestoration as aG, type ParamKeyValuePair as aa, type SubmitOptions as ab, type URLSearchParamsInit as ac, type SubmitTarget as ad, createSearchParams as ae, type StaticRouterProps as af, type StaticRouterProviderProps as ag, createStaticHandler as ah, createStaticRouter as ai, StaticRouter as aj, StaticRouterProvider as ak, Meta as al, Links as am, Scripts as an, PrefetchPageLinks as ao, type ScriptsProps as ap, type HandleDataRequestFunction as aq, type HandleDocumentRequestFunction as ar, type HandleErrorFunction as as, type ServerEntryModule as at, hydrationRouteProperties as au, mapRouteProperties as av, WithComponentProps as aw, withComponentProps as ax, WithHydrateFallbackProps as ay, withHydrateFallbackProps as az, type AwaitProps as b, type MemoryRouterProps as c, type RouteProps as d, type RouterProps as e, type RouterProviderProps as f, type RoutesProps as g, Await as h, MemoryRouter as i, Navigate as j, Outlet as k, Route$1 as l, Router as m, RouterProvider as n, Routes as o, createMemoryRouter as p, createRoutesFromChildren as q, createRoutesFromElements as r, renderMatches as s, type HashRouterProps as t, type HistoryRouterProps as u, type LinkProps as v, type NavLinkProps as w, type NavLinkRenderProps as x, type FetcherFormProps as y, type FormProps as z };