react-router 7.5.3 → 7.6.0

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 (40) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/development/{chunk-AYJ5UCUI.mjs → chunk-D4RADZKF.mjs} +903 -139
  3. package/dist/development/dom-export.d.mts +2 -2
  4. package/dist/development/dom-export.d.ts +1 -2
  5. package/dist/development/dom-export.js +34 -6102
  6. package/dist/development/dom-export.mjs +6 -3
  7. package/dist/development/index.d.mts +33 -67
  8. package/dist/development/index.d.ts +1893 -197
  9. package/dist/development/index.js +905 -141
  10. package/dist/development/index.mjs +2 -2
  11. package/dist/development/lib/types/route-module.d.mts +1 -2
  12. package/dist/development/lib/types/route-module.d.ts +1 -2
  13. package/dist/development/lib/types/route-module.js +1 -1
  14. package/dist/development/lib/types/route-module.mjs +1 -1
  15. package/dist/{production/fog-of-war-BLArG-qZ.d.ts → development/lib-CCSAGgcP.d.mts} +57 -12
  16. package/dist/{production/route-data-C12CLHiN.d.mts → development/route-data-B9_30zbP.d.ts} +11 -1
  17. package/dist/development/{route-data-C12CLHiN.d.mts → route-data-C6QaL0wu.d.mts} +11 -1
  18. package/dist/production/{chunk-KKWFQRUV.mjs → chunk-CVXGOGHQ.mjs} +903 -139
  19. package/dist/production/dom-export.d.mts +2 -2
  20. package/dist/production/dom-export.d.ts +1 -2
  21. package/dist/production/dom-export.js +34 -6102
  22. package/dist/production/dom-export.mjs +6 -3
  23. package/dist/production/index.d.mts +33 -67
  24. package/dist/production/index.d.ts +1893 -197
  25. package/dist/production/index.js +905 -141
  26. package/dist/production/index.mjs +2 -2
  27. package/dist/production/lib/types/route-module.d.mts +1 -2
  28. package/dist/production/lib/types/route-module.d.ts +1 -2
  29. package/dist/production/lib/types/route-module.js +1 -1
  30. package/dist/production/lib/types/route-module.mjs +1 -1
  31. package/dist/{development/fog-of-war-BLArG-qZ.d.ts → production/lib-CCSAGgcP.d.mts} +57 -12
  32. package/dist/{development/route-data-C12CLHiN.d.ts → production/route-data-B9_30zbP.d.ts} +11 -1
  33. package/dist/production/{route-data-C12CLHiN.d.ts → route-data-C6QaL0wu.d.mts} +11 -1
  34. package/package.json +5 -3
  35. package/dist/development/data-CQbyyGzl.d.mts +0 -11
  36. package/dist/development/data-CQbyyGzl.d.ts +0 -11
  37. package/dist/development/fog-of-war-D2zsXvum.d.mts +0 -1691
  38. package/dist/production/data-CQbyyGzl.d.mts +0 -11
  39. package/dist/production/data-CQbyyGzl.d.ts +0 -11
  40. package/dist/production/fog-of-war-D2zsXvum.d.mts +0 -1691
@@ -1,1691 +0,0 @@
1
- import * as React from 'react';
2
- import { k as RouteObject, R as RouterInit, F as FutureConfig$1, H as HydrationState, I as InitialEntry, D as DataStrategyFunction, at as PatchRoutesOnNavigationFunction, a as Router$1, T as To, d as RelativeRoutingType, y as NonIndexRouteObject, a5 as LazyRouteFunction, s as IndexRouteObject, e as Location, f as Action, as as Navigator, av as RouteMatch, p as StaticHandlerContext, c as RouteManifest, b as RouteModules, G as DataRouteObject, J as ClientLoaderFunction, a4 as HTMLFormMethod, a2 as FormEncType, aD as PageLinkDescriptor, aT as History, O as GetScrollRestorationKeyFunction, N as NavigateOptions, Q as Fetcher, n as SerializeFrom, B as BlockerFunction } from './route-data-C12CLHiN.mjs';
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
-
415
- type SerializedError = {
416
- message: string;
417
- stack?: string;
418
- };
419
- interface FrameworkContextObject {
420
- manifest: AssetsManifest;
421
- routeModules: RouteModules;
422
- criticalCss?: CriticalCss;
423
- serverHandoffString?: string;
424
- future: FutureConfig;
425
- ssr: boolean;
426
- isSpaMode: boolean;
427
- serializeError?(error: Error): SerializedError;
428
- renderMeta?: {
429
- didRenderScripts?: boolean;
430
- streamCache?: Record<number, Promise<void> & {
431
- result?: {
432
- done: boolean;
433
- value: string;
434
- };
435
- error?: unknown;
436
- }>;
437
- };
438
- }
439
- interface EntryContext extends FrameworkContextObject {
440
- staticHandlerContext: StaticHandlerContext;
441
- serverHandoffStream?: ReadableStream<Uint8Array>;
442
- }
443
- interface FutureConfig {
444
- unstable_subResourceIntegrity: boolean;
445
- unstable_middleware: boolean;
446
- }
447
- type CriticalCss = string | {
448
- rel: "stylesheet";
449
- href: string;
450
- };
451
- interface AssetsManifest {
452
- entry: {
453
- imports: string[];
454
- module: string;
455
- };
456
- routes: RouteManifest<EntryRoute>;
457
- url: string;
458
- version: string;
459
- hmr?: {
460
- timestamp?: number;
461
- runtime: string;
462
- };
463
- sri?: Record<string, string> | true;
464
- }
465
-
466
- interface Route {
467
- index?: boolean;
468
- caseSensitive?: boolean;
469
- id: string;
470
- parentId?: string;
471
- path?: string;
472
- }
473
- interface EntryRoute extends Route {
474
- hasAction: boolean;
475
- hasLoader: boolean;
476
- hasClientAction: boolean;
477
- hasClientLoader: boolean;
478
- hasClientMiddleware: boolean;
479
- hasErrorBoundary: boolean;
480
- imports?: string[];
481
- css?: string[];
482
- module: string;
483
- clientActionModule: string | undefined;
484
- clientLoaderModule: string | undefined;
485
- clientMiddlewareModule: string | undefined;
486
- hydrateFallbackModule: string | undefined;
487
- parentId?: string;
488
- }
489
- declare function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation: Set<string>, manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState, ssr: boolean, isSpaMode: boolean): DataRouteObject[];
490
- 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[];
491
- declare function shouldHydrateRouteLoader(routeId: string, clientLoader: ClientLoaderFunction | undefined, hasLoader: boolean, isSpaMode: boolean): boolean;
492
-
493
- type ParamKeyValuePair = [string, string];
494
- type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
495
- /**
496
- Creates a URLSearchParams object using the given initializer.
497
-
498
- This is identical to `new URLSearchParams(init)` except it also
499
- supports arrays as values in the object form of the initializer
500
- instead of just strings. This is convenient when you need multiple
501
- values for a given key, but don't want to use an array initializer.
502
-
503
- For example, instead of:
504
-
505
- ```tsx
506
- let searchParams = new URLSearchParams([
507
- ['sort', 'name'],
508
- ['sort', 'price']
509
- ]);
510
- ```
511
- you can do:
512
-
513
- ```
514
- let searchParams = createSearchParams({
515
- sort: ['name', 'price']
516
- });
517
- ```
518
-
519
- @category Utils
520
- */
521
- declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
522
- type JsonObject = {
523
- [Key in string]: JsonValue;
524
- } & {
525
- [Key in string]?: JsonValue | undefined;
526
- };
527
- type JsonArray = JsonValue[] | readonly JsonValue[];
528
- type JsonPrimitive = string | number | boolean | null;
529
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
530
- type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | JsonValue | null;
531
- /**
532
- * Submit options shared by both navigations and fetchers
533
- */
534
- interface SharedSubmitOptions {
535
- /**
536
- * The HTTP method used to submit the form. Overrides `<form method>`.
537
- * Defaults to "GET".
538
- */
539
- method?: HTMLFormMethod;
540
- /**
541
- * The action URL path used to submit the form. Overrides `<form action>`.
542
- * Defaults to the path of the current route.
543
- */
544
- action?: string;
545
- /**
546
- * The encoding used to submit the form. Overrides `<form encType>`.
547
- * Defaults to "application/x-www-form-urlencoded".
548
- */
549
- encType?: FormEncType;
550
- /**
551
- * Determines whether the form action is relative to the route hierarchy or
552
- * the pathname. Use this if you want to opt out of navigating the route
553
- * hierarchy and want to instead route based on /-delimited URL segments
554
- */
555
- relative?: RelativeRoutingType;
556
- /**
557
- * In browser-based environments, prevent resetting scroll after this
558
- * navigation when using the <ScrollRestoration> component
559
- */
560
- preventScrollReset?: boolean;
561
- /**
562
- * Enable flushSync for this submission's state updates
563
- */
564
- flushSync?: boolean;
565
- }
566
- /**
567
- * Submit options available to fetchers
568
- */
569
- interface FetcherSubmitOptions extends SharedSubmitOptions {
570
- }
571
- /**
572
- * Submit options available to navigations
573
- */
574
- interface SubmitOptions extends FetcherSubmitOptions {
575
- /**
576
- * Set `true` to replace the current entry in the browser's history stack
577
- * instead of creating a new one (i.e. stay on "the same page"). Defaults
578
- * to `false`.
579
- */
580
- replace?: boolean;
581
- /**
582
- * State object to add to the history stack entry for this navigation
583
- */
584
- state?: any;
585
- /**
586
- * Indicate a specific fetcherKey to use when using navigate=false
587
- */
588
- fetcherKey?: string;
589
- /**
590
- * navigate=false will use a fetcher instead of a navigation
591
- */
592
- navigate?: boolean;
593
- /**
594
- * Enable view transitions on this submission navigation
595
- */
596
- viewTransition?: boolean;
597
- }
598
-
599
- declare const FrameworkContext: React.Context<FrameworkContextObject | undefined>;
600
- /**
601
- * Defines the discovery behavior of the link:
602
- *
603
- * - "render" - default, discover the route when the link renders
604
- * - "none" - don't eagerly discover, only discover if the link is clicked
605
- */
606
- type DiscoverBehavior = "render" | "none";
607
- /**
608
- * Defines the prefetching behavior of the link:
609
- *
610
- * - "none": Never fetched
611
- * - "intent": Fetched when the user focuses or hovers the link
612
- * - "render": Fetched when the link is rendered
613
- * - "viewport": Fetched when the link is in the viewport
614
- */
615
- type PrefetchBehavior = "intent" | "render" | "none" | "viewport";
616
- /**
617
- Renders all of the `<link>` tags created by route module {@link LinksFunction} export. You should render it inside the `<head>` of your document.
618
-
619
- ```tsx
620
- import { Links } from "react-router";
621
-
622
- export default function Root() {
623
- return (
624
- <html>
625
- <head>
626
- <Links />
627
- </head>
628
- <body></body>
629
- </html>
630
- );
631
- }
632
- ```
633
-
634
- @category Components
635
- */
636
- declare function Links(): React.JSX.Element;
637
- /**
638
- 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.
639
-
640
- ```tsx
641
- import { PrefetchPageLinks } from "react-router"
642
-
643
- <PrefetchPageLinks page="/absolute/path" />
644
- ```
645
-
646
- 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.
647
-
648
- @category Components
649
- */
650
- declare function PrefetchPageLinks({ page, ...dataLinkProps }: PageLinkDescriptor): React.JSX.Element | null;
651
- /**
652
- Renders all the `<meta>` tags created by route module {@link MetaFunction} exports. You should render it inside the `<head>` of your HTML.
653
-
654
- ```tsx
655
- import { Meta } from "react-router";
656
-
657
- export default function Root() {
658
- return (
659
- <html>
660
- <head>
661
- <Meta />
662
- </head>
663
- </html>
664
- );
665
- }
666
- ```
667
-
668
- @category Components
669
- */
670
- declare function Meta(): React.JSX.Element;
671
- /**
672
- A couple common attributes:
673
-
674
- - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
675
- - `<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.
676
-
677
- You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
678
-
679
- @category Types
680
- */
681
- type ScriptsProps = Omit<React.HTMLProps<HTMLScriptElement>, "children" | "async" | "defer" | "src" | "type" | "noModule" | "dangerouslySetInnerHTML" | "suppressHydrationWarning">;
682
- /**
683
- Renders the client runtime of your app. It should be rendered inside the `<body>` of the document.
684
-
685
- ```tsx
686
- import { Scripts } from "react-router";
687
-
688
- export default function Root() {
689
- return (
690
- <html>
691
- <head />
692
- <body>
693
- <Scripts />
694
- </body>
695
- </html>
696
- );
697
- }
698
- ```
699
-
700
- 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.
701
-
702
- @category Components
703
- */
704
- declare function Scripts(props: ScriptsProps): React.JSX.Element | null;
705
-
706
- declare global {
707
- const REACT_ROUTER_VERSION: string;
708
- }
709
- /**
710
- * @category Routers
711
- */
712
- interface DOMRouterOpts {
713
- /**
714
- * Basename path for the application.
715
- */
716
- basename?: string;
717
- /**
718
- * Function to provide the initial context values for all client side navigations/fetches
719
- */
720
- unstable_getContext?: RouterInit["unstable_getContext"];
721
- /**
722
- * Future flags to enable for the router.
723
- */
724
- future?: Partial<FutureConfig$1>;
725
- /**
726
- * Hydration data to initialize the router with if you have already performed
727
- * data loading on the server.
728
- */
729
- hydrationData?: HydrationState;
730
- /**
731
- * Override the default data strategy of loading in parallel.
732
- * Only intended for advanced usage.
733
- */
734
- dataStrategy?: DataStrategyFunction;
735
- /**
736
- * Lazily define portions of the route tree on navigations.
737
- */
738
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
739
- /**
740
- * Window object override - defaults to the global `window` instance.
741
- */
742
- window?: Window;
743
- }
744
- /**
745
- * Create a new data router that manages the application path via `history.pushState`
746
- * and `history.replaceState`.
747
- *
748
- * @category Data Routers
749
- */
750
- declare function createBrowserRouter(
751
- /**
752
- * Application routes
753
- */
754
- routes: RouteObject[],
755
- /**
756
- * Router options
757
- */
758
- opts?: DOMRouterOpts): Router$1;
759
- /**
760
- * Create a new data router that manages the application path via the URL hash
761
- *
762
- * @category Data Routers
763
- */
764
- declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router$1;
765
- /**
766
- * @category Types
767
- */
768
- interface BrowserRouterProps {
769
- basename?: string;
770
- children?: React.ReactNode;
771
- window?: Window;
772
- }
773
- /**
774
- * A `<Router>` for use in web browsers. Provides the cleanest URLs.
775
- *
776
- * @category Component Routers
777
- */
778
- declare function BrowserRouter({ basename, children, window, }: BrowserRouterProps): React.JSX.Element;
779
- /**
780
- * @category Types
781
- */
782
- interface HashRouterProps {
783
- basename?: string;
784
- children?: React.ReactNode;
785
- window?: Window;
786
- }
787
- /**
788
- * A `<Router>` for use in web browsers. Stores the location in the hash
789
- * portion of the URL so it is not sent to the server.
790
- *
791
- * @category Component Routers
792
- */
793
- declare function HashRouter({ basename, children, window }: HashRouterProps): React.JSX.Element;
794
- /**
795
- * @category Types
796
- */
797
- interface HistoryRouterProps {
798
- basename?: string;
799
- children?: React.ReactNode;
800
- history: History;
801
- }
802
- /**
803
- * A `<Router>` that accepts a pre-instantiated history object. It's important
804
- * to note that using your own history object is highly discouraged and may add
805
- * two versions of the history library to your bundles unless you use the same
806
- * version of the history library that React Router uses internally.
807
- *
808
- * @name unstable_HistoryRouter
809
- * @category Component Routers
810
- */
811
- declare function HistoryRouter({ basename, children, history, }: HistoryRouterProps): React.JSX.Element;
812
- declare namespace HistoryRouter {
813
- var displayName: string;
814
- }
815
- /**
816
- * @category Types
817
- */
818
- interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
819
- /**
820
- Defines the link discovery behavior
821
-
822
- ```tsx
823
- <Link /> // default ("render")
824
- <Link discover="render" />
825
- <Link discover="none" />
826
- ```
827
-
828
- - **render** - default, discover the route when the link renders
829
- - **none** - don't eagerly discover, only discover if the link is clicked
830
- */
831
- discover?: DiscoverBehavior;
832
- /**
833
- Defines the data and module prefetching behavior for the link.
834
-
835
- ```tsx
836
- <Link /> // default
837
- <Link prefetch="none" />
838
- <Link prefetch="intent" />
839
- <Link prefetch="render" />
840
- <Link prefetch="viewport" />
841
- ```
842
-
843
- - **none** - default, no prefetching
844
- - **intent** - prefetches when the user hovers or focuses the link
845
- - **render** - prefetches when the link renders
846
- - **viewport** - prefetches when the link is in the viewport, very useful for mobile
847
-
848
- Prefetching is done with HTML `<link rel="prefetch">` tags. They are inserted after the link.
849
-
850
- ```tsx
851
- <a href="..." />
852
- <a href="..." />
853
- <link rel="prefetch" /> // might conditionally render
854
- ```
855
-
856
- 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).
857
- */
858
- prefetch?: PrefetchBehavior;
859
- /**
860
- 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>`).
861
-
862
- ```tsx
863
- <Link to="/logout" reloadDocument />
864
- ```
865
- */
866
- reloadDocument?: boolean;
867
- /**
868
- Replaces the current entry in the history stack instead of pushing a new one onto it.
869
-
870
- ```tsx
871
- <Link replace />
872
- ```
873
-
874
- ```
875
- # with a history stack like this
876
- A -> B
877
-
878
- # normal link click pushes a new entry
879
- A -> B -> C
880
-
881
- # but with `replace`, B is replaced by C
882
- A -> C
883
- ```
884
- */
885
- replace?: boolean;
886
- /**
887
- Adds persistent client side routing state to the next location.
888
-
889
- ```tsx
890
- <Link to="/somewhere/else" state={{ some: "value" }} />
891
- ```
892
-
893
- The location state is accessed from the `location`.
894
-
895
- ```tsx
896
- function SomeComp() {
897
- const location = useLocation()
898
- location.state; // { some: "value" }
899
- }
900
- ```
901
-
902
- 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)
903
- */
904
- state?: any;
905
- /**
906
- 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.
907
-
908
- ```tsx
909
- <Link to="?tab=one" preventScrollReset />
910
- ```
911
- */
912
- preventScrollReset?: boolean;
913
- /**
914
- Defines the relative path behavior for the link.
915
-
916
- ```tsx
917
- <Link to=".." /> // default: "route"
918
- <Link relative="route" />
919
- <Link relative="path" />
920
- ```
921
-
922
- Consider a route hierarchy where a parent route pattern is "blog" and a child route pattern is "blog/:slug/edit".
923
-
924
- - **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".
925
- - **path** - relative to the path so `..` will only remove one URL segment up to "/blog/:slug"
926
- */
927
- relative?: RelativeRoutingType;
928
- /**
929
- Can be a string or a partial {@link Path}:
930
-
931
- ```tsx
932
- <Link to="/some/path" />
933
-
934
- <Link
935
- to={{
936
- pathname: "/some/path",
937
- search: "?query=string",
938
- hash: "#hash",
939
- }}
940
- />
941
- ```
942
- */
943
- to: To;
944
- /**
945
- Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) for this navigation.
946
-
947
- ```jsx
948
- <Link to={to} viewTransition>
949
- Click me
950
- </Link>
951
- ```
952
-
953
- To apply specific styles for the transition, see {@link useViewTransitionState}
954
- */
955
- viewTransition?: boolean;
956
- }
957
- /**
958
- A progressively enhanced `<a href>` wrapper to enable navigation with client-side routing.
959
-
960
- ```tsx
961
- import { Link } from "react-router";
962
-
963
- <Link to="/dashboard">Dashboard</Link>;
964
-
965
- <Link
966
- to={{
967
- pathname: "/some/path",
968
- search: "?query=string",
969
- hash: "#hash",
970
- }}
971
- />
972
- ```
973
-
974
- @category Components
975
- */
976
- declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
977
- /**
978
- The object passed to {@link NavLink} `children`, `className`, and `style` prop callbacks to render and style the link based on its state.
979
-
980
- ```
981
- // className
982
- <NavLink
983
- to="/messages"
984
- className={({ isActive, isPending }) =>
985
- isPending ? "pending" : isActive ? "active" : ""
986
- }
987
- >
988
- Messages
989
- </NavLink>
990
-
991
- // style
992
- <NavLink
993
- to="/messages"
994
- style={({ isActive, isPending }) => {
995
- return {
996
- fontWeight: isActive ? "bold" : "",
997
- color: isPending ? "red" : "black",
998
- }
999
- )}
1000
- />
1001
-
1002
- // children
1003
- <NavLink to="/tasks">
1004
- {({ isActive, isPending }) => (
1005
- <span className={isActive ? "active" : ""}>Tasks</span>
1006
- )}
1007
- </NavLink>
1008
- ```
1009
-
1010
- */
1011
- type NavLinkRenderProps = {
1012
- /**
1013
- * Indicates if the link's URL matches the current location.
1014
- */
1015
- isActive: boolean;
1016
- /**
1017
- * Indicates if the pending location matches the link's URL.
1018
- */
1019
- isPending: boolean;
1020
- /**
1021
- * Indicates if a view transition to the link's URL is in progress. See {@link useViewTransitionState}
1022
- */
1023
- isTransitioning: boolean;
1024
- };
1025
- /**
1026
- * @category Types
1027
- */
1028
- interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
1029
- /**
1030
- Can be regular React children or a function that receives an object with the active and pending states of the link.
1031
-
1032
- ```tsx
1033
- <NavLink to="/tasks">
1034
- {({ isActive }) => (
1035
- <span className={isActive ? "active" : ""}>Tasks</span>
1036
- )}
1037
- </NavLink>
1038
- ```
1039
- */
1040
- children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode);
1041
- /**
1042
- Changes the matching logic to make it case-sensitive:
1043
-
1044
- | Link | URL | isActive |
1045
- | -------------------------------------------- | ------------- | -------- |
1046
- | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
1047
- | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
1048
- */
1049
- caseSensitive?: boolean;
1050
- /**
1051
- Classes are automatically applied to NavLink that correspond to {@link NavLinkRenderProps}.
1052
-
1053
- ```css
1054
- a.active { color: red; }
1055
- a.pending { color: blue; }
1056
- a.transitioning {
1057
- view-transition-name: my-transition;
1058
- }
1059
- ```
1060
- */
1061
- className?: string | ((props: NavLinkRenderProps) => string | undefined);
1062
- /**
1063
- 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.
1064
-
1065
- | Link | URL | isActive |
1066
- | ----------------------------- | ------------ | -------- |
1067
- | `<NavLink to="/tasks" />` | `/tasks` | true |
1068
- | `<NavLink to="/tasks" />` | `/tasks/123` | true |
1069
- | `<NavLink to="/tasks" end />` | `/tasks` | true |
1070
- | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
1071
-
1072
- `<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.
1073
- */
1074
- end?: boolean;
1075
- style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined);
1076
- }
1077
- /**
1078
- Wraps {@link Link | `<Link>`} with additional props for styling active and pending states.
1079
-
1080
- - Automatically applies classes to the link based on its active and pending states, see {@link NavLinkProps.className}.
1081
- - 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.
1082
-
1083
- ```tsx
1084
- import { NavLink } from "react-router"
1085
- <NavLink to="/message" />
1086
- ```
1087
-
1088
- States are available through the className, style, and children render props. See {@link NavLinkRenderProps}.
1089
-
1090
- ```tsx
1091
- <NavLink
1092
- to="/messages"
1093
- className={({ isActive, isPending }) =>
1094
- isPending ? "pending" : isActive ? "active" : ""
1095
- }
1096
- >
1097
- Messages
1098
- </NavLink>
1099
- ```
1100
-
1101
- @category Components
1102
- */
1103
- declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
1104
- /**
1105
- * Form props shared by navigations and fetchers
1106
- */
1107
- interface SharedFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
1108
- /**
1109
- * The HTTP verb to use when the form is submitted. Supports "get", "post",
1110
- * "put", "delete", and "patch".
1111
- *
1112
- * Native `<form>` only supports `get` and `post`, avoid the other verbs if
1113
- * you'd like to support progressive enhancement
1114
- */
1115
- method?: HTMLFormMethod;
1116
- /**
1117
- * The encoding type to use for the form submission.
1118
- */
1119
- encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
1120
- /**
1121
- * The URL to submit the form data to. If `undefined`, this defaults to the closest route in context.
1122
- */
1123
- action?: string;
1124
- /**
1125
- * Determines whether the form action is relative to the route hierarchy or
1126
- * the pathname. Use this if you want to opt out of navigating the route
1127
- * hierarchy and want to instead route based on /-delimited URL segments
1128
- */
1129
- relative?: RelativeRoutingType;
1130
- /**
1131
- * Prevent the scroll position from resetting to the top of the viewport on
1132
- * completion of the navigation when using the <ScrollRestoration> component
1133
- */
1134
- preventScrollReset?: boolean;
1135
- /**
1136
- * A function to call when the form is submitted. If you call
1137
- * `event.preventDefault()` then this form will not do anything.
1138
- */
1139
- onSubmit?: React.FormEventHandler<HTMLFormElement>;
1140
- }
1141
- /**
1142
- * Form props available to fetchers
1143
- * @category Types
1144
- */
1145
- interface FetcherFormProps extends SharedFormProps {
1146
- }
1147
- /**
1148
- * Form props available to navigations
1149
- * @category Types
1150
- */
1151
- interface FormProps extends SharedFormProps {
1152
- discover?: DiscoverBehavior;
1153
- /**
1154
- * Indicates a specific fetcherKey to use when using `navigate={false}` so you
1155
- * can pick up the fetcher's state in a different component in a {@link
1156
- * useFetcher}.
1157
- */
1158
- fetcherKey?: string;
1159
- /**
1160
- * Skips the navigation and uses a {@link useFetcher | fetcher} internally
1161
- * when `false`. This is essentially a shorthand for `useFetcher()` +
1162
- * `<fetcher.Form>` where you don't care about the resulting data in this
1163
- * component.
1164
- */
1165
- navigate?: boolean;
1166
- /**
1167
- * Forces a full document navigation instead of client side routing + data
1168
- * fetch.
1169
- */
1170
- reloadDocument?: boolean;
1171
- /**
1172
- * Replaces the current entry in the browser history stack when the form
1173
- * navigates. Use this if you don't want the user to be able to click "back"
1174
- * to the page with the form on it.
1175
- */
1176
- replace?: boolean;
1177
- /**
1178
- * State object to add to the history stack entry for this navigation
1179
- */
1180
- state?: any;
1181
- /**
1182
- * Enables a [View
1183
- * Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
1184
- * for this navigation. To apply specific styles during the transition see
1185
- * {@link useViewTransitionState}.
1186
- */
1187
- viewTransition?: boolean;
1188
- }
1189
- /**
1190
-
1191
- 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.
1192
-
1193
- 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.
1194
-
1195
- 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].
1196
-
1197
- ```tsx
1198
- import { Form } from "react-router";
1199
-
1200
- function NewEvent() {
1201
- return (
1202
- <Form action="/events" method="post">
1203
- <input name="title" type="text" />
1204
- <input name="description" type="text" />
1205
- </Form>
1206
- )
1207
- }
1208
- ```
1209
-
1210
- @category Components
1211
- */
1212
- declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
1213
- type ScrollRestorationProps = ScriptsProps & {
1214
- /**
1215
- Defines the key used to restore scroll positions.
1216
-
1217
- ```tsx
1218
- <ScrollRestoration
1219
- getKey={(location, matches) => {
1220
- // default behavior
1221
- return location.key
1222
- }}
1223
- />
1224
- ```
1225
- */
1226
- getKey?: GetScrollRestorationKeyFunction;
1227
- storageKey?: string;
1228
- };
1229
- /**
1230
- Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
1231
-
1232
- ```tsx
1233
- import { ScrollRestoration } from "react-router";
1234
-
1235
- export default function Root() {
1236
- return (
1237
- <html>
1238
- <body>
1239
- <ScrollRestoration />
1240
- <Scripts />
1241
- </body>
1242
- </html>
1243
- );
1244
- }
1245
- ```
1246
-
1247
- 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.
1248
-
1249
- ```tsx
1250
- <ScrollRestoration nonce={cspNonce} />
1251
- ```
1252
-
1253
- @category Components
1254
- */
1255
- declare function ScrollRestoration({ getKey, storageKey, ...props }: ScrollRestorationProps): React.JSX.Element | null;
1256
- declare namespace ScrollRestoration {
1257
- var displayName: string;
1258
- }
1259
- /**
1260
- * Handles the click behavior for router `<Link>` components. This is useful if
1261
- * you need to create custom `<Link>` components with the same click behavior we
1262
- * use in our exported `<Link>`.
1263
- *
1264
- * @category Hooks
1265
- */
1266
- declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, viewTransition, }?: {
1267
- target?: React.HTMLAttributeAnchorTarget;
1268
- replace?: boolean;
1269
- state?: any;
1270
- preventScrollReset?: boolean;
1271
- relative?: RelativeRoutingType;
1272
- viewTransition?: boolean;
1273
- }): (event: React.MouseEvent<E, MouseEvent>) => void;
1274
- /**
1275
- Returns a tuple of the current URL's {@link URLSearchParams} and a function to update them. Setting the search params causes a navigation.
1276
-
1277
- ```tsx
1278
- import { useSearchParams } from "react-router";
1279
-
1280
- export function SomeComponent() {
1281
- const [searchParams, setSearchParams] = useSearchParams();
1282
- // ...
1283
- }
1284
- ```
1285
-
1286
- @category Hooks
1287
- */
1288
- declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
1289
- /**
1290
- Sets new search params and causes a navigation when called.
1291
-
1292
- ```tsx
1293
- <button
1294
- onClick={() => {
1295
- const params = new URLSearchParams();
1296
- params.set("someKey", "someValue");
1297
- setSearchParams(params, {
1298
- preventScrollReset: true,
1299
- });
1300
- }}
1301
- />
1302
- ```
1303
-
1304
- It also supports a function for setting new search params.
1305
-
1306
- ```tsx
1307
- <button
1308
- onClick={() => {
1309
- setSearchParams((prev) => {
1310
- prev.set("someKey", "someValue");
1311
- return prev;
1312
- });
1313
- }}
1314
- />
1315
- ```
1316
- */
1317
- type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
1318
- /**
1319
- * Submits a HTML `<form>` to the server without reloading the page.
1320
- */
1321
- interface SubmitFunction {
1322
- (
1323
- /**
1324
- Can be multiple types of elements and objects
1325
-
1326
- **`HTMLFormElement`**
1327
-
1328
- ```tsx
1329
- <Form
1330
- onSubmit={(event) => {
1331
- submit(event.currentTarget);
1332
- }}
1333
- />
1334
- ```
1335
-
1336
- **`FormData`**
1337
-
1338
- ```tsx
1339
- const formData = new FormData();
1340
- formData.append("myKey", "myValue");
1341
- submit(formData, { method: "post" });
1342
- ```
1343
-
1344
- **Plain object that will be serialized as `FormData`**
1345
-
1346
- ```tsx
1347
- submit({ myKey: "myValue" }, { method: "post" });
1348
- ```
1349
-
1350
- **Plain object that will be serialized as JSON**
1351
-
1352
- ```tsx
1353
- submit(
1354
- { myKey: "myValue" },
1355
- { method: "post", encType: "application/json" }
1356
- );
1357
- ```
1358
- */
1359
- target: SubmitTarget,
1360
- /**
1361
- * Options that override the `<form>`'s own attributes. Required when
1362
- * submitting arbitrary data without a backing `<form>`.
1363
- */
1364
- options?: SubmitOptions): Promise<void>;
1365
- }
1366
- /**
1367
- * Submits a fetcher `<form>` to the server without reloading the page.
1368
- */
1369
- interface FetcherSubmitFunction {
1370
- (
1371
- /**
1372
- Can be multiple types of elements and objects
1373
-
1374
- **`HTMLFormElement`**
1375
-
1376
- ```tsx
1377
- <fetcher.Form
1378
- onSubmit={(event) => {
1379
- fetcher.submit(event.currentTarget);
1380
- }}
1381
- />
1382
- ```
1383
-
1384
- **`FormData`**
1385
-
1386
- ```tsx
1387
- const formData = new FormData();
1388
- formData.append("myKey", "myValue");
1389
- fetcher.submit(formData, { method: "post" });
1390
- ```
1391
-
1392
- **Plain object that will be serialized as `FormData`**
1393
-
1394
- ```tsx
1395
- fetcher.submit({ myKey: "myValue" }, { method: "post" });
1396
- ```
1397
-
1398
- **Plain object that will be serialized as JSON**
1399
-
1400
- ```tsx
1401
- fetcher.submit(
1402
- { myKey: "myValue" },
1403
- { method: "post", encType: "application/json" }
1404
- );
1405
- ```
1406
-
1407
- */
1408
- target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
1409
- }
1410
- /**
1411
- The imperative version of {@link Form | `<Form>`} that lets you submit a form from code instead of a user interaction.
1412
-
1413
- ```tsx
1414
- import { useSubmit } from "react-router";
1415
-
1416
- function SomeComponent() {
1417
- const submit = useSubmit();
1418
- return (
1419
- <Form
1420
- onChange={(event) => {
1421
- submit(event.currentTarget);
1422
- }}
1423
- />
1424
- );
1425
- }
1426
- ```
1427
-
1428
- @category Hooks
1429
- */
1430
- declare function useSubmit(): SubmitFunction;
1431
- /**
1432
- Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.
1433
-
1434
- This is used internally by {@link Form} resolve the action to the closest route, but can be used generically as well.
1435
-
1436
- ```tsx
1437
- import { useFormAction } from "react-router";
1438
-
1439
- function SomeComponent() {
1440
- // closest route URL
1441
- let action = useFormAction();
1442
-
1443
- // closest route URL + "destroy"
1444
- let destroyAction = useFormAction("destroy");
1445
- }
1446
- ```
1447
-
1448
- @category Hooks
1449
- */
1450
- declare function useFormAction(
1451
- /**
1452
- * The action to append to the closest route URL.
1453
- */
1454
- action?: string, { relative }?: {
1455
- relative?: RelativeRoutingType;
1456
- }): string;
1457
- /**
1458
- The return value of `useFetcher` that keeps track of the state of a fetcher.
1459
-
1460
- ```tsx
1461
- let fetcher = useFetcher();
1462
- ```
1463
- */
1464
- type FetcherWithComponents<TData> = Fetcher<TData> & {
1465
- /**
1466
- Just like {@link Form} except it doesn't cause a navigation.
1467
-
1468
- ```tsx
1469
- function SomeComponent() {
1470
- const fetcher = useFetcher()
1471
- return (
1472
- <fetcher.Form method="post" action="/some/route">
1473
- <input type="text" />
1474
- </fetcher.Form>
1475
- )
1476
- }
1477
- ```
1478
- */
1479
- Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
1480
- /**
1481
- Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
1482
-
1483
- The `formData` can be multiple types:
1484
-
1485
- - [`FormData`][form_data] - A `FormData` instance.
1486
- - [`HTMLFormElement`][html_form_element] - A [`<form>`][form_element] DOM element.
1487
- - `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.
1488
-
1489
- 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.
1490
-
1491
- ```tsx
1492
- // Submit a FormData instance (GET request)
1493
- const formData = new FormData();
1494
- fetcher.submit(formData);
1495
-
1496
- // Submit the HTML form element
1497
- fetcher.submit(event.currentTarget.form, {
1498
- method: "POST",
1499
- });
1500
-
1501
- // Submit key/value JSON as a FormData instance
1502
- fetcher.submit(
1503
- { serialized: "values" },
1504
- { method: "POST" }
1505
- );
1506
-
1507
- // Submit raw JSON
1508
- fetcher.submit(
1509
- {
1510
- deeply: {
1511
- nested: {
1512
- json: "values",
1513
- },
1514
- },
1515
- },
1516
- {
1517
- method: "POST",
1518
- encType: "application/json",
1519
- }
1520
- );
1521
- ```
1522
- */
1523
- submit: FetcherSubmitFunction;
1524
- /**
1525
- 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.
1526
-
1527
- ```tsx
1528
- let fetcher = useFetcher()
1529
-
1530
- <input onChange={e => {
1531
- fetcher.load(`/search?q=${e.target.value}`)
1532
- }} />
1533
- ```
1534
- */
1535
- load: (href: string, opts?: {
1536
- /**
1537
- * Wraps the initial state update for this `fetcher.load` in a
1538
- * `ReactDOM.flushSync` call instead of the default `React.startTransition`.
1539
- * This allows you to perform synchronous DOM actions immediately after the
1540
- * update is flushed to the DOM.
1541
- */
1542
- flushSync?: boolean;
1543
- }) => Promise<void>;
1544
- };
1545
- /**
1546
- Useful for creating complex, dynamic user interfaces that require multiple, concurrent data interactions without causing a navigation.
1547
-
1548
- Fetchers track their own, independent state and can be used to load data, submit forms, and generally interact with loaders and actions.
1549
-
1550
- ```tsx
1551
- import { useFetcher } from "react-router"
1552
-
1553
- function SomeComponent() {
1554
- let fetcher = useFetcher()
1555
-
1556
- // states are available on the fetcher
1557
- fetcher.state // "idle" | "loading" | "submitting"
1558
- fetcher.data // the data returned from the action or loader
1559
-
1560
- // render a form
1561
- <fetcher.Form method="post" />
1562
-
1563
- // load data
1564
- fetcher.load("/some/route")
1565
-
1566
- // submit data
1567
- fetcher.submit(someFormRef, { method: "post" })
1568
- fetcher.submit(someData, {
1569
- method: "post",
1570
- encType: "application/json"
1571
- })
1572
- }
1573
- ```
1574
-
1575
- @category Hooks
1576
- */
1577
- declare function useFetcher<T = any>({ key, }?: {
1578
- /**
1579
- 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:
1580
-
1581
- ```tsx
1582
- function SomeComp() {
1583
- let fetcher = useFetcher({ key: "my-key" })
1584
- // ...
1585
- }
1586
-
1587
- // Somewhere else
1588
- function AnotherComp() {
1589
- // this will be the same fetcher, sharing the state across the app
1590
- let fetcher = useFetcher({ key: "my-key" });
1591
- // ...
1592
- }
1593
- ```
1594
- */
1595
- key?: string;
1596
- }): FetcherWithComponents<SerializeFrom<T>>;
1597
- /**
1598
- 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.
1599
-
1600
- ```tsx
1601
- import { useFetchers } from "react-router";
1602
-
1603
- function SomeComponent() {
1604
- const fetchers = useFetchers();
1605
- fetchers[0].formData; // FormData
1606
- fetchers[0].state; // etc.
1607
- // ...
1608
- }
1609
- ```
1610
-
1611
- @category Hooks
1612
- */
1613
- declare function useFetchers(): (Fetcher & {
1614
- key: string;
1615
- })[];
1616
- /**
1617
- * When rendered inside a RouterProvider, will restore scroll positions on navigations
1618
- */
1619
- declare function useScrollRestoration({ getKey, storageKey, }?: {
1620
- getKey?: GetScrollRestorationKeyFunction;
1621
- storageKey?: string;
1622
- }): void;
1623
- /**
1624
- * Setup a callback to be fired on the window's `beforeunload` event.
1625
- *
1626
- * @category Hooks
1627
- */
1628
- declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
1629
- capture?: boolean;
1630
- }): void;
1631
- /**
1632
- Wrapper around useBlocker to show a window.confirm prompt to users instead of building a custom UI with {@link useBlocker}.
1633
-
1634
- 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.
1635
-
1636
- ```tsx
1637
- function ImportantForm() {
1638
- let [value, setValue] = React.useState("");
1639
-
1640
- // Block navigating elsewhere when data has been entered into the input
1641
- unstable_usePrompt({
1642
- message: "Are you sure?",
1643
- when: ({ currentLocation, nextLocation }) =>
1644
- value !== "" &&
1645
- currentLocation.pathname !== nextLocation.pathname,
1646
- });
1647
-
1648
- return (
1649
- <Form method="post">
1650
- <label>
1651
- Enter some important data:
1652
- <input
1653
- name="data"
1654
- value={value}
1655
- onChange={(e) => setValue(e.target.value)}
1656
- />
1657
- </label>
1658
- <button type="submit">Save</button>
1659
- </Form>
1660
- );
1661
- }
1662
- ```
1663
-
1664
- @category Hooks
1665
- @name unstable_usePrompt
1666
- */
1667
- declare function usePrompt({ when, message, }: {
1668
- when: boolean | BlockerFunction;
1669
- message: string;
1670
- }): void;
1671
- /**
1672
- 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)
1673
-
1674
- @category Hooks
1675
- @name useViewTransitionState
1676
- */
1677
- declare function useViewTransitionState(to: To, opts?: {
1678
- relative?: RelativeRoutingType;
1679
- }): boolean;
1680
-
1681
- declare global {
1682
- interface Navigator {
1683
- connection?: {
1684
- saveData: boolean;
1685
- };
1686
- }
1687
- }
1688
- declare function getPatchRoutesOnNavigationFunction(manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, isSpaMode: boolean, basename: string | undefined): PatchRoutesOnNavigationFunction | undefined;
1689
- declare function useFogOFWarDiscovery(router: Router$1, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, isSpaMode: boolean): void;
1690
-
1691
- export { useSearchParams as $, type AssetsManifest as A, type BrowserRouterProps as B, type CriticalCss as C, type DOMRouterOpts as D, type EntryContext as E, type FutureConfig as F, type FetcherSubmitFunction as G, type HashRouterProps as H, type IndexRouteProps as I, type FetcherWithComponents as J, createBrowserRouter as K, type LayoutRouteProps as L, type MemoryRouterOpts as M, type NavigateProps as N, type OutletProps as O, type PathRouteProps as P, createHashRouter as Q, type RouterProviderProps as R, type ScrollRestorationProps as S, BrowserRouter as T, HashRouter as U, Link as V, HistoryRouter as W, NavLink as X, Form as Y, ScrollRestoration as Z, useLinkClickHandler as _, type Route as a, useSubmit as a0, useFormAction as a1, useFetcher as a2, useFetchers as a3, useBeforeUnload as a4, usePrompt as a5, useViewTransitionState as a6, type FetcherSubmitOptions as a7, type ParamKeyValuePair as a8, type SubmitOptions as a9, type URLSearchParamsInit as aa, type SubmitTarget as ab, createSearchParams as ac, Meta as ad, Links as ae, Scripts as af, PrefetchPageLinks as ag, type ScriptsProps as ah, hydrationRouteProperties as ai, mapRouteProperties as aj, FrameworkContext as ak, getPatchRoutesOnNavigationFunction as al, useFogOFWarDiscovery as am, createClientRoutes as an, createClientRoutesWithHMRRevalidationOptOut as ao, shouldHydrateRouteLoader as ap, useScrollRestoration as aq, type AwaitProps as b, type MemoryRouterProps as c, type RouteProps as d, type RouterProps as e, type RoutesProps as f, Await as g, MemoryRouter as h, Navigate as i, Outlet as j, Route$1 as k, Router as l, RouterProvider as m, Routes as n, createMemoryRouter as o, createRoutesFromChildren as p, createRoutesFromElements as q, renderMatches as r, type HistoryRouterProps as s, type LinkProps as t, type NavLinkProps as u, type NavLinkRenderProps as v, type FetcherFormProps as w, type FormProps as x, type SetURLSearchParams as y, type SubmitFunction as z };