react-router 0.0.0-experimental-1ebb6d403 → 0.0.0-experimental-e41ede670

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 (44) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/dist/development/{chunk-5XVYBMAF.mjs → chunk-H3OBLXFX.mjs} +767 -514
  3. package/dist/development/dom-export.d.mts +13 -3
  4. package/dist/development/dom-export.d.ts +13 -3
  5. package/dist/development/dom-export.js +272 -108
  6. package/dist/development/dom-export.mjs +9 -6
  7. package/dist/{production/fog-of-war-7V7BguJA.d.ts → development/fog-of-war-Bt7PejVF.d.ts} +91 -6
  8. package/dist/development/{fog-of-war-NQCW9yWR.d.mts → fog-of-war-Dz4n-TU-.d.mts} +91 -6
  9. package/dist/development/index.d.mts +10 -19
  10. package/dist/development/index.d.ts +10 -19
  11. package/dist/development/index.js +767 -514
  12. package/dist/development/index.mjs +2 -2
  13. package/dist/development/lib/types/route-module.d.mts +6 -2
  14. package/dist/development/lib/types/route-module.d.ts +6 -2
  15. package/dist/development/lib/types/route-module.js +1 -1
  16. package/dist/development/lib/types/route-module.mjs +1 -1
  17. package/dist/development/{route-data-JFOfNyPS.d.ts → route-data-C96IyGKo.d.mts} +37 -15
  18. package/dist/{production/route-data-JFOfNyPS.d.mts → development/route-data-C96IyGKo.d.ts} +37 -15
  19. package/dist/production/{chunk-CKFZHSMW.mjs → chunk-YBZNESR7.mjs} +767 -514
  20. package/dist/production/dom-export.d.mts +13 -3
  21. package/dist/production/dom-export.d.ts +13 -3
  22. package/dist/production/dom-export.js +272 -108
  23. package/dist/production/dom-export.mjs +9 -6
  24. package/dist/{development/fog-of-war-7V7BguJA.d.ts → production/fog-of-war-Bt7PejVF.d.ts} +91 -6
  25. package/dist/production/{fog-of-war-NQCW9yWR.d.mts → fog-of-war-Dz4n-TU-.d.mts} +91 -6
  26. package/dist/production/index.d.mts +10 -19
  27. package/dist/production/index.d.ts +10 -19
  28. package/dist/production/index.js +767 -514
  29. package/dist/production/index.mjs +2 -2
  30. package/dist/production/lib/types/route-module.d.mts +6 -2
  31. package/dist/production/lib/types/route-module.d.ts +6 -2
  32. package/dist/production/lib/types/route-module.js +1 -1
  33. package/dist/production/lib/types/route-module.mjs +1 -1
  34. package/dist/production/{route-data-JFOfNyPS.d.ts → route-data-C96IyGKo.d.mts} +37 -15
  35. package/dist/{development/route-data-JFOfNyPS.d.mts → production/route-data-C96IyGKo.d.ts} +37 -15
  36. package/package.json +2 -17
  37. package/dist/development/server.d.mts +0 -988
  38. package/dist/development/server.d.ts +0 -988
  39. package/dist/development/server.js +0 -1429
  40. package/dist/development/server.mjs +0 -1406
  41. package/dist/production/server.d.mts +0 -988
  42. package/dist/production/server.d.ts +0 -988
  43. package/dist/production/server.js +0 -1405
  44. package/dist/production/server.mjs +0 -1382
@@ -1,988 +0,0 @@
1
- import * as React from 'react';
2
-
3
- /**
4
- * Actions represent the type of change to a location value.
5
- */
6
- declare enum Action {
7
- /**
8
- * A POP indicates a change to an arbitrary index in the history stack, such
9
- * as a back or forward navigation. It does not describe the direction of the
10
- * navigation, only that the current index changed.
11
- *
12
- * Note: This is the default action for newly created history objects.
13
- */
14
- Pop = "POP",
15
- /**
16
- * A PUSH indicates a new entry being added to the history stack, such as when
17
- * a link is clicked and a new page loads. When this happens, all subsequent
18
- * entries in the stack are lost.
19
- */
20
- Push = "PUSH",
21
- /**
22
- * A REPLACE indicates the entry at the current index in the history stack
23
- * being replaced by a new one.
24
- */
25
- Replace = "REPLACE"
26
- }
27
- /**
28
- * The pathname, search, and hash values of a URL.
29
- */
30
- interface Path {
31
- /**
32
- * A URL pathname, beginning with a /.
33
- */
34
- pathname: string;
35
- /**
36
- * A URL search string, beginning with a ?.
37
- */
38
- search: string;
39
- /**
40
- * A URL fragment identifier, beginning with a #.
41
- */
42
- hash: string;
43
- }
44
- /**
45
- * An entry in a history stack. A location contains information about the
46
- * URL path, as well as possibly some arbitrary state and a key.
47
- */
48
- interface Location<State = any> extends Path {
49
- /**
50
- * A value of arbitrary data associated with this location.
51
- */
52
- state: State;
53
- /**
54
- * A unique string associated with this location. May be used to safely store
55
- * and retrieve data in some other storage API, like `localStorage`.
56
- *
57
- * Note: This value is always "default" on the initial location.
58
- */
59
- key: string;
60
- }
61
- /**
62
- * A change to the current location.
63
- */
64
- interface Update {
65
- /**
66
- * The action that triggered the change.
67
- */
68
- action: Action;
69
- /**
70
- * The new location.
71
- */
72
- location: Location;
73
- /**
74
- * The delta between this location and the former location in the history stack
75
- */
76
- delta: number | null;
77
- }
78
- /**
79
- * A function that receives notifications about location changes.
80
- */
81
- interface Listener {
82
- (update: Update): void;
83
- }
84
- /**
85
- * Describes a location that is the destination of some navigation used in
86
- * {@link Link}, {@link useNavigate}, etc.
87
- */
88
- type To = string | Partial<Path>;
89
- /**
90
- * A history is an interface to the navigation stack. The history serves as the
91
- * source of truth for the current location, as well as provides a set of
92
- * methods that may be used to change it.
93
- *
94
- * It is similar to the DOM's `window.history` object, but with a smaller, more
95
- * focused API.
96
- */
97
- interface History {
98
- /**
99
- * The last action that modified the current location. This will always be
100
- * Action.Pop when a history instance is first created. This value is mutable.
101
- */
102
- readonly action: Action;
103
- /**
104
- * The current location. This value is mutable.
105
- */
106
- readonly location: Location;
107
- /**
108
- * Returns a valid href for the given `to` value that may be used as
109
- * the value of an <a href> attribute.
110
- *
111
- * @param to - The destination URL
112
- */
113
- createHref(to: To): string;
114
- /**
115
- * Returns a URL for the given `to` value
116
- *
117
- * @param to - The destination URL
118
- */
119
- createURL(to: To): URL;
120
- /**
121
- * Encode a location the same way window.history would do (no-op for memory
122
- * history) so we ensure our PUSH/REPLACE navigations for data routers
123
- * behave the same as POP
124
- *
125
- * @param to Unencoded path
126
- */
127
- encodeLocation(to: To): Path;
128
- /**
129
- * Pushes a new location onto the history stack, increasing its length by one.
130
- * If there were any entries in the stack after the current one, they are
131
- * lost.
132
- *
133
- * @param to - The new URL
134
- * @param state - Data to associate with the new location
135
- */
136
- push(to: To, state?: any): void;
137
- /**
138
- * Replaces the current location in the history stack with a new one. The
139
- * location that was replaced will no longer be available.
140
- *
141
- * @param to - The new URL
142
- * @param state - Data to associate with the new location
143
- */
144
- replace(to: To, state?: any): void;
145
- /**
146
- * Navigates `n` entries backward/forward in the history stack relative to the
147
- * current index. For example, a "back" navigation would use go(-1).
148
- *
149
- * @param delta - The delta in the stack index
150
- */
151
- go(delta: number): void;
152
- /**
153
- * Sets up a listener that will be called whenever the current location
154
- * changes.
155
- *
156
- * @param listener - A function that will be called when the location changes
157
- * @returns unlisten - A function that may be used to stop listening
158
- */
159
- listen(listener: Listener): () => void;
160
- }
161
-
162
- /**
163
- * Map of routeId -> data returned from a loader/action/error
164
- */
165
- interface RouteData {
166
- [routeId: string]: any;
167
- }
168
- type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
169
- type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
170
- /**
171
- * Users can specify either lowercase or uppercase form methods on `<Form>`,
172
- * useSubmit(), `<fetcher.Form>`, etc.
173
- */
174
- type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
175
- /**
176
- * Active navigation/fetcher form methods are exposed in uppercase on the
177
- * RouterState. This is to align with the normalization done via fetch().
178
- */
179
- type FormMethod = UpperCaseFormMethod;
180
- type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
181
- type JsonObject = {
182
- [Key in string]: JsonValue;
183
- } & {
184
- [Key in string]?: JsonValue | undefined;
185
- };
186
- type JsonArray = JsonValue[] | readonly JsonValue[];
187
- type JsonPrimitive = string | number | boolean | null;
188
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
189
- /**
190
- * @private
191
- * Internal interface to pass around for action submissions, not intended for
192
- * external consumption
193
- */
194
- type Submission = {
195
- formMethod: FormMethod;
196
- formAction: string;
197
- formEncType: FormEncType;
198
- formData: FormData;
199
- json: undefined;
200
- text: undefined;
201
- } | {
202
- formMethod: FormMethod;
203
- formAction: string;
204
- formEncType: FormEncType;
205
- formData: undefined;
206
- json: JsonValue;
207
- text: undefined;
208
- } | {
209
- formMethod: FormMethod;
210
- formAction: string;
211
- formEncType: FormEncType;
212
- formData: undefined;
213
- json: undefined;
214
- text: string;
215
- };
216
- /**
217
- * @private
218
- * Arguments passed to route loader/action functions. Same for now but we keep
219
- * this as a private implementation detail in case they diverge in the future.
220
- */
221
- interface DataFunctionArgs<Context> {
222
- request: Request;
223
- params: Params;
224
- context?: Context;
225
- }
226
- /**
227
- * Arguments passed to loader functions
228
- */
229
- interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
230
- }
231
- /**
232
- * Arguments passed to action functions
233
- */
234
- interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
235
- }
236
- /**
237
- * Loaders and actions can return anything except `undefined` (`null` is a
238
- * valid return value if there is no data to return). Responses are preferred
239
- * and will ease any future migration to Remix
240
- */
241
- type DataFunctionValue = Response | NonNullable<unknown> | null;
242
- type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
243
- /**
244
- * Route loader function signature
245
- */
246
- type LoaderFunction<Context = any> = {
247
- (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
248
- } & {
249
- hydrate?: boolean;
250
- };
251
- /**
252
- * Route action function signature
253
- */
254
- interface ActionFunction<Context = any> {
255
- (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
256
- }
257
- /**
258
- * Arguments passed to shouldRevalidate function
259
- */
260
- interface ShouldRevalidateFunctionArgs {
261
- currentUrl: URL;
262
- currentParams: AgnosticDataRouteMatch["params"];
263
- nextUrl: URL;
264
- nextParams: AgnosticDataRouteMatch["params"];
265
- formMethod?: Submission["formMethod"];
266
- formAction?: Submission["formAction"];
267
- formEncType?: Submission["formEncType"];
268
- text?: Submission["text"];
269
- formData?: Submission["formData"];
270
- json?: Submission["json"];
271
- actionStatus?: number;
272
- actionResult?: any;
273
- defaultShouldRevalidate: boolean;
274
- }
275
- /**
276
- * Route shouldRevalidate function signature. This runs after any submission
277
- * (navigation or fetcher), so we flatten the navigation/fetcher submission
278
- * onto the arguments. It shouldn't matter whether it came from a navigation
279
- * or a fetcher, what really matters is the URLs and the formData since loaders
280
- * have to re-run based on the data models that were potentially mutated.
281
- */
282
- interface ShouldRevalidateFunction {
283
- (args: ShouldRevalidateFunctionArgs): boolean;
284
- }
285
- interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
286
- shouldLoad: boolean;
287
- resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
288
- }
289
- interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
290
- matches: DataStrategyMatch[];
291
- fetcherKey: string | null;
292
- }
293
- /**
294
- * Result from a loader or action called via dataStrategy
295
- */
296
- interface DataStrategyResult {
297
- type: "data" | "error";
298
- result: unknown;
299
- }
300
- interface DataStrategyFunction {
301
- (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
302
- }
303
- type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
304
- path: string;
305
- matches: M[];
306
- patch: (routeId: string | null, children: O[]) => void;
307
- };
308
- type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => void | Promise<void>;
309
- /**
310
- * Function provided by the framework-aware layers to set any framework-specific
311
- * properties from framework-agnostic properties
312
- */
313
- interface MapRoutePropertiesFunction {
314
- (route: AgnosticRouteObject): {
315
- hasErrorBoundary: boolean;
316
- } & Record<string, any>;
317
- }
318
- /**
319
- * Keys we cannot change from within a lazy() function. We spread all other keys
320
- * onto the route. Either they're meaningful to the router, or they'll get
321
- * ignored.
322
- */
323
- type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
324
- type RequireOne<T, Key = keyof T> = Exclude<{
325
- [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
326
- }[keyof T], undefined>;
327
- /**
328
- * lazy() function to load a route definition, which can add non-matching
329
- * related properties to a route
330
- */
331
- interface LazyRouteFunction<R extends AgnosticRouteObject> {
332
- (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
333
- }
334
- /**
335
- * Base RouteObject with common props shared by all types of routes
336
- */
337
- type AgnosticBaseRouteObject = {
338
- caseSensitive?: boolean;
339
- path?: string;
340
- id?: string;
341
- loader?: LoaderFunction | boolean;
342
- action?: ActionFunction | boolean;
343
- hasErrorBoundary?: boolean;
344
- shouldRevalidate?: ShouldRevalidateFunction;
345
- handle?: any;
346
- lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
347
- };
348
- /**
349
- * Index routes must not have children
350
- */
351
- type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
352
- children?: undefined;
353
- index: true;
354
- };
355
- /**
356
- * Non-index routes may have children, but cannot have index
357
- */
358
- type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
359
- children?: AgnosticRouteObject[];
360
- index?: false;
361
- };
362
- /**
363
- * A route object represents a logical route, with (optionally) its child
364
- * routes organized in a tree-like structure.
365
- */
366
- type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
367
- type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
368
- id: string;
369
- };
370
- type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
371
- children?: AgnosticDataRouteObject[];
372
- id: string;
373
- };
374
- /**
375
- * A data route object, which is just a RouteObject with a required unique ID
376
- */
377
- type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
378
- /**
379
- * The parameters that were parsed from the URL path.
380
- */
381
- type Params<Key extends string = string> = {
382
- readonly [key in Key]: string | undefined;
383
- };
384
- /**
385
- * A RouteMatch contains info about how a route matched a URL.
386
- */
387
- interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
388
- /**
389
- * The names and values of dynamic parameters in the URL.
390
- */
391
- params: Params<ParamKey>;
392
- /**
393
- * The portion of the URL pathname that was matched.
394
- */
395
- pathname: string;
396
- /**
397
- * The portion of the URL pathname that was matched before child routes.
398
- */
399
- pathnameBase: string;
400
- /**
401
- * The route object that was used to match.
402
- */
403
- route: RouteObjectType;
404
- }
405
- interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
406
- }
407
- /**
408
- * Matches the given routes to a location and returns the match data.
409
- *
410
- * @category Utils
411
- */
412
- declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
413
- interface UIMatch<Data = unknown, Handle = unknown> {
414
- id: string;
415
- pathname: string;
416
- params: AgnosticRouteMatch["params"];
417
- data: Data;
418
- handle: Handle;
419
- }
420
-
421
- /**
422
- * A Router instance manages all navigation and data loading/mutations
423
- */
424
- interface Router {
425
- /**
426
- * @private
427
- * PRIVATE - DO NOT USE
428
- *
429
- * Return the basename for the router
430
- */
431
- get basename(): RouterInit["basename"];
432
- /**
433
- * @private
434
- * PRIVATE - DO NOT USE
435
- *
436
- * Return the future config for the router
437
- */
438
- get future(): FutureConfig;
439
- /**
440
- * @private
441
- * PRIVATE - DO NOT USE
442
- *
443
- * Return the current state of the router
444
- */
445
- get state(): RouterState;
446
- /**
447
- * @private
448
- * PRIVATE - DO NOT USE
449
- *
450
- * Return the routes for this router instance
451
- */
452
- get routes(): AgnosticDataRouteObject[];
453
- /**
454
- * @private
455
- * PRIVATE - DO NOT USE
456
- *
457
- * Return the window associated with the router
458
- */
459
- get window(): RouterInit["window"];
460
- /**
461
- * @private
462
- * PRIVATE - DO NOT USE
463
- *
464
- * Initialize the router, including adding history listeners and kicking off
465
- * initial data fetches. Returns a function to cleanup listeners and abort
466
- * any in-progress loads
467
- */
468
- initialize(): Router;
469
- /**
470
- * @private
471
- * PRIVATE - DO NOT USE
472
- *
473
- * Subscribe to router.state updates
474
- *
475
- * @param fn function to call with the new state
476
- */
477
- subscribe(fn: RouterSubscriber): () => void;
478
- /**
479
- * @private
480
- * PRIVATE - DO NOT USE
481
- *
482
- * Enable scroll restoration behavior in the router
483
- *
484
- * @param savedScrollPositions Object that will manage positions, in case
485
- * it's being restored from sessionStorage
486
- * @param getScrollPosition Function to get the active Y scroll position
487
- * @param getKey Function to get the key to use for restoration
488
- */
489
- enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
490
- /**
491
- * @private
492
- * PRIVATE - DO NOT USE
493
- *
494
- * Navigate forward/backward in the history stack
495
- * @param to Delta to move in the history stack
496
- */
497
- navigate(to: number): Promise<void>;
498
- /**
499
- * Navigate to the given path
500
- * @param to Path to navigate to
501
- * @param opts Navigation options (method, submission, etc.)
502
- */
503
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
504
- /**
505
- * @private
506
- * PRIVATE - DO NOT USE
507
- *
508
- * Trigger a fetcher load/submission
509
- *
510
- * @param key Fetcher key
511
- * @param routeId Route that owns the fetcher
512
- * @param href href to fetch
513
- * @param opts Fetcher options, (method, submission, etc.)
514
- */
515
- fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
516
- /**
517
- * @private
518
- * PRIVATE - DO NOT USE
519
- *
520
- * Trigger a revalidation of all current route loaders and fetcher loads
521
- */
522
- revalidate(): Promise<void>;
523
- /**
524
- * @private
525
- * PRIVATE - DO NOT USE
526
- *
527
- * Utility function to create an href for the given location
528
- * @param location
529
- */
530
- createHref(location: Location | URL): string;
531
- /**
532
- * @private
533
- * PRIVATE - DO NOT USE
534
- *
535
- * Utility function to URL encode a destination path according to the internal
536
- * history implementation
537
- * @param to
538
- */
539
- encodeLocation(to: To): Path;
540
- /**
541
- * @private
542
- * PRIVATE - DO NOT USE
543
- *
544
- * Get/create a fetcher for the given key
545
- * @param key
546
- */
547
- getFetcher<TData = any>(key: string): Fetcher<TData>;
548
- /**
549
- * @private
550
- * PRIVATE - DO NOT USE
551
- *
552
- * Delete the fetcher for a given key
553
- * @param key
554
- */
555
- deleteFetcher(key: string): void;
556
- /**
557
- * @private
558
- * PRIVATE - DO NOT USE
559
- *
560
- * Cleanup listeners and abort any in-progress loads
561
- */
562
- dispose(): void;
563
- /**
564
- * @private
565
- * PRIVATE - DO NOT USE
566
- *
567
- * Get a navigation blocker
568
- * @param key The identifier for the blocker
569
- * @param fn The blocker function implementation
570
- */
571
- getBlocker(key: string, fn: BlockerFunction): Blocker;
572
- /**
573
- * @private
574
- * PRIVATE - DO NOT USE
575
- *
576
- * Delete a navigation blocker
577
- * @param key The identifier for the blocker
578
- */
579
- deleteBlocker(key: string): void;
580
- /**
581
- * @private
582
- * PRIVATE DO NOT USE
583
- *
584
- * Patch additional children routes into an existing parent route
585
- * @param routeId The parent route id or a callback function accepting `patch`
586
- * to perform batch patching
587
- * @param children The additional children routes
588
- */
589
- patchRoutes(routeId: string | null, children: AgnosticRouteObject[]): void;
590
- /**
591
- * @private
592
- * PRIVATE - DO NOT USE
593
- *
594
- * HMR needs to pass in-flight route updates to React Router
595
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
596
- */
597
- _internalSetRoutes(routes: AgnosticRouteObject[]): void;
598
- /**
599
- * @private
600
- * PRIVATE - DO NOT USE
601
- *
602
- * Internal fetch AbortControllers accessed by unit tests
603
- */
604
- _internalFetchControllers: Map<string, AbortController>;
605
- }
606
- /**
607
- * State maintained internally by the router. During a navigation, all states
608
- * reflect the the "old" location unless otherwise noted.
609
- */
610
- interface RouterState {
611
- /**
612
- * The action of the most recent navigation
613
- */
614
- historyAction: Action;
615
- /**
616
- * The current location reflected by the router
617
- */
618
- location: Location;
619
- /**
620
- * The current set of route matches
621
- */
622
- matches: AgnosticDataRouteMatch[];
623
- /**
624
- * Tracks whether we've completed our initial data load
625
- */
626
- initialized: boolean;
627
- /**
628
- * Current scroll position we should start at for a new view
629
- * - number -> scroll position to restore to
630
- * - false -> do not restore scroll at all (used during submissions)
631
- * - null -> don't have a saved position, scroll to hash or top of page
632
- */
633
- restoreScrollPosition: number | false | null;
634
- /**
635
- * Indicate whether this navigation should skip resetting the scroll position
636
- * if we are unable to restore the scroll position
637
- */
638
- preventScrollReset: boolean;
639
- /**
640
- * Tracks the state of the current navigation
641
- */
642
- navigation: Navigation;
643
- /**
644
- * Tracks any in-progress revalidations
645
- */
646
- revalidation: RevalidationState;
647
- /**
648
- * Data from the loaders for the current matches
649
- */
650
- loaderData: RouteData;
651
- /**
652
- * Data from the action for the current matches
653
- */
654
- actionData: RouteData | null;
655
- /**
656
- * Errors caught from loaders for the current matches
657
- */
658
- errors: RouteData | null;
659
- /**
660
- * Map of current fetchers
661
- */
662
- fetchers: Map<string, Fetcher>;
663
- /**
664
- * Map of current blockers
665
- */
666
- blockers: Map<string, Blocker>;
667
- }
668
- /**
669
- * Data that can be passed into hydrate a Router from SSR
670
- */
671
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
672
- /**
673
- * Future flags to toggle new feature behavior
674
- */
675
- interface FutureConfig {
676
- }
677
- /**
678
- * Initialization options for createRouter
679
- */
680
- interface RouterInit {
681
- routes: AgnosticRouteObject[];
682
- history: History;
683
- basename?: string;
684
- mapRouteProperties?: MapRoutePropertiesFunction;
685
- future?: Partial<FutureConfig>;
686
- hydrationData?: HydrationState;
687
- window?: Window;
688
- dataStrategy?: DataStrategyFunction;
689
- patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
690
- }
691
- /**
692
- * State returned from a server-side query() call
693
- */
694
- interface StaticHandlerContext {
695
- basename: Router["basename"];
696
- location: RouterState["location"];
697
- matches: RouterState["matches"];
698
- loaderData: RouterState["loaderData"];
699
- actionData: RouterState["actionData"];
700
- errors: RouterState["errors"];
701
- statusCode: number;
702
- loaderHeaders: Record<string, Headers>;
703
- actionHeaders: Record<string, Headers>;
704
- _deepestRenderedBoundaryId?: string | null;
705
- }
706
- /**
707
- * A StaticHandler instance manages a singular SSR navigation/fetch event
708
- */
709
- interface StaticHandler {
710
- dataRoutes: AgnosticDataRouteObject[];
711
- query(request: Request, opts?: {
712
- requestContext?: unknown;
713
- skipLoaderErrorBubbling?: boolean;
714
- dataStrategy?: DataStrategyFunction;
715
- }): Promise<StaticHandlerContext | Response>;
716
- queryRoute(request: Request, opts?: {
717
- routeId?: string;
718
- requestContext?: unknown;
719
- dataStrategy?: DataStrategyFunction;
720
- }): Promise<any>;
721
- }
722
- type ViewTransitionOpts = {
723
- currentLocation: Location;
724
- nextLocation: Location;
725
- };
726
- /**
727
- * Subscriber function signature for changes to router state
728
- */
729
- interface RouterSubscriber {
730
- (state: RouterState, opts: {
731
- deletedFetchers: string[];
732
- viewTransitionOpts?: ViewTransitionOpts;
733
- flushSync: boolean;
734
- }): void;
735
- }
736
- /**
737
- * Function signature for determining the key to be used in scroll restoration
738
- * for a given location
739
- */
740
- interface GetScrollRestorationKeyFunction {
741
- (location: Location, matches: UIMatch[]): string | null;
742
- }
743
- /**
744
- * Function signature for determining the current scroll position
745
- */
746
- interface GetScrollPositionFunction {
747
- (): number;
748
- }
749
- /**
750
- - "route": relative to the route hierarchy so `..` means remove all segments of the current route even if it has many. For example, a `route("posts/:id")` would have both `:id` and `posts` removed from the url.
751
- - "path": relative to the pathname so `..` means remove one segment of the pathname. For example, a `route("posts/:id")` would have only `:id` removed from the url.
752
- */
753
- type RelativeRoutingType = "route" | "path";
754
- type BaseNavigateOrFetchOptions = {
755
- preventScrollReset?: boolean;
756
- relative?: RelativeRoutingType;
757
- flushSync?: boolean;
758
- };
759
- type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
760
- replace?: boolean;
761
- state?: any;
762
- fromRouteId?: string;
763
- viewTransition?: boolean;
764
- };
765
- type BaseSubmissionOptions = {
766
- formMethod?: HTMLFormMethod;
767
- formEncType?: FormEncType;
768
- } & ({
769
- formData: FormData;
770
- body?: undefined;
771
- } | {
772
- formData?: undefined;
773
- body: any;
774
- });
775
- /**
776
- * Options for a navigate() call for a normal (non-submission) navigation
777
- */
778
- type LinkNavigateOptions = BaseNavigateOptions;
779
- /**
780
- * Options for a navigate() call for a submission navigation
781
- */
782
- type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
783
- /**
784
- * Options to pass to navigate() for a navigation
785
- */
786
- type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
787
- /**
788
- * Options for a fetch() load
789
- */
790
- type LoadFetchOptions = BaseNavigateOrFetchOptions;
791
- /**
792
- * Options for a fetch() submission
793
- */
794
- type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
795
- /**
796
- * Options to pass to fetch()
797
- */
798
- type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
799
- /**
800
- * Potential states for state.navigation
801
- */
802
- type NavigationStates = {
803
- Idle: {
804
- state: "idle";
805
- location: undefined;
806
- formMethod: undefined;
807
- formAction: undefined;
808
- formEncType: undefined;
809
- formData: undefined;
810
- json: undefined;
811
- text: undefined;
812
- };
813
- Loading: {
814
- state: "loading";
815
- location: Location;
816
- formMethod: Submission["formMethod"] | undefined;
817
- formAction: Submission["formAction"] | undefined;
818
- formEncType: Submission["formEncType"] | undefined;
819
- formData: Submission["formData"] | undefined;
820
- json: Submission["json"] | undefined;
821
- text: Submission["text"] | undefined;
822
- };
823
- Submitting: {
824
- state: "submitting";
825
- location: Location;
826
- formMethod: Submission["formMethod"];
827
- formAction: Submission["formAction"];
828
- formEncType: Submission["formEncType"];
829
- formData: Submission["formData"];
830
- json: Submission["json"];
831
- text: Submission["text"];
832
- };
833
- };
834
- type Navigation = NavigationStates[keyof NavigationStates];
835
- type RevalidationState = "idle" | "loading";
836
- /**
837
- * Potential states for fetchers
838
- */
839
- type FetcherStates<TData = any> = {
840
- /**
841
- * The fetcher is not calling a loader or action
842
- *
843
- * ```tsx
844
- * fetcher.state === "idle"
845
- * ```
846
- */
847
- Idle: {
848
- state: "idle";
849
- formMethod: undefined;
850
- formAction: undefined;
851
- formEncType: undefined;
852
- text: undefined;
853
- formData: undefined;
854
- json: undefined;
855
- /**
856
- * If the fetcher has never been called, this will be undefined.
857
- */
858
- data: TData | undefined;
859
- };
860
- /**
861
- * The fetcher is loading data from a {@link LoaderFunction | loader} from a
862
- * call to {@link FetcherWithComponents.load | `fetcher.load`}.
863
- *
864
- * ```tsx
865
- * // somewhere
866
- * <button onClick={() => fetcher.load("/some/route") }>Load</button>
867
- *
868
- * // the state will update
869
- * fetcher.state === "loading"
870
- * ```
871
- */
872
- Loading: {
873
- state: "loading";
874
- formMethod: Submission["formMethod"] | undefined;
875
- formAction: Submission["formAction"] | undefined;
876
- formEncType: Submission["formEncType"] | undefined;
877
- text: Submission["text"] | undefined;
878
- formData: Submission["formData"] | undefined;
879
- json: Submission["json"] | undefined;
880
- data: TData | undefined;
881
- };
882
- /**
883
- The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
884
-
885
- ```tsx
886
- // somewhere
887
- <input
888
- onChange={e => {
889
- fetcher.submit(event.currentTarget.form, { method: "post" });
890
- }}
891
- />
892
-
893
- // the state will update
894
- fetcher.state === "submitting"
895
-
896
- // and formData will be available
897
- fetcher.formData
898
- ```
899
- */
900
- Submitting: {
901
- state: "submitting";
902
- formMethod: Submission["formMethod"];
903
- formAction: Submission["formAction"];
904
- formEncType: Submission["formEncType"];
905
- text: Submission["text"];
906
- formData: Submission["formData"];
907
- json: Submission["json"];
908
- data: TData | undefined;
909
- };
910
- };
911
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
912
- interface BlockerBlocked {
913
- state: "blocked";
914
- reset(): void;
915
- proceed(): void;
916
- location: Location;
917
- }
918
- interface BlockerUnblocked {
919
- state: "unblocked";
920
- reset: undefined;
921
- proceed: undefined;
922
- location: undefined;
923
- }
924
- interface BlockerProceeding {
925
- state: "proceeding";
926
- reset: undefined;
927
- proceed: undefined;
928
- location: Location;
929
- }
930
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
931
- type BlockerFunction = (args: {
932
- currentLocation: Location;
933
- nextLocation: Location;
934
- historyAction: Action;
935
- }) => boolean;
936
- interface CreateStaticHandlerOptions$1 {
937
- basename?: string;
938
- mapRouteProperties?: MapRoutePropertiesFunction;
939
- future?: {};
940
- }
941
-
942
- interface IndexRouteObject {
943
- caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
944
- path?: AgnosticIndexRouteObject["path"];
945
- id?: AgnosticIndexRouteObject["id"];
946
- loader?: AgnosticIndexRouteObject["loader"];
947
- action?: AgnosticIndexRouteObject["action"];
948
- hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
949
- shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
950
- handle?: AgnosticIndexRouteObject["handle"];
951
- index: true;
952
- children?: undefined;
953
- element?: React.ReactNode | null;
954
- hydrateFallbackElement?: React.ReactNode | null;
955
- errorElement?: React.ReactNode | null;
956
- Component?: React.ComponentType | null;
957
- HydrateFallback?: React.ComponentType | null;
958
- ErrorBoundary?: React.ComponentType | null;
959
- lazy?: LazyRouteFunction<RouteObject>;
960
- }
961
- interface NonIndexRouteObject {
962
- caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
963
- path?: AgnosticNonIndexRouteObject["path"];
964
- id?: AgnosticNonIndexRouteObject["id"];
965
- loader?: AgnosticNonIndexRouteObject["loader"];
966
- action?: AgnosticNonIndexRouteObject["action"];
967
- hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
968
- shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
969
- handle?: AgnosticNonIndexRouteObject["handle"];
970
- index?: false;
971
- children?: RouteObject[];
972
- element?: React.ReactNode | null;
973
- hydrateFallbackElement?: React.ReactNode | null;
974
- errorElement?: React.ReactNode | null;
975
- Component?: React.ComponentType | null;
976
- HydrateFallback?: React.ComponentType | null;
977
- ErrorBoundary?: React.ComponentType | null;
978
- lazy?: LazyRouteFunction<RouteObject>;
979
- }
980
- type RouteObject = IndexRouteObject | NonIndexRouteObject;
981
-
982
- type CreateStaticHandlerOptions = Omit<CreateStaticHandlerOptions$1, "mapRouteProperties">;
983
- /**
984
- * @category Utils
985
- */
986
- declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
987
-
988
- export { createStaticHandler, matchRoutes };