react-router 6.26.2 → 7.0.0-pre.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.
- package/CHANGELOG.md +307 -0
- package/README.md +1 -14
- package/dist/dom-export.d.ts +3 -0
- package/dist/dom-export.mjs +205 -0
- package/dist/dom-export.mjs.map +1 -0
- package/dist/index.d.ts +74 -29
- package/dist/index.mjs +11551 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/components.d.ts +250 -35
- package/dist/lib/context.d.ts +20 -7
- package/dist/lib/dom/dom.d.ts +123 -0
- package/dist/lib/dom/global.d.ts +40 -0
- package/dist/lib/dom/lib.d.ts +940 -0
- package/dist/lib/dom/server.d.ts +41 -0
- package/dist/lib/dom/ssr/components.d.ts +123 -0
- package/dist/lib/dom/ssr/data.d.ts +7 -0
- package/dist/lib/dom/ssr/entry.d.ts +47 -0
- package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
- package/dist/lib/dom/ssr/errors.d.ts +2 -0
- package/dist/lib/dom/ssr/fallback.d.ts +2 -0
- package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
- package/dist/lib/dom/ssr/invariant.d.ts +2 -0
- package/dist/lib/dom/ssr/links.d.ts +25 -0
- package/dist/lib/dom/ssr/markup.d.ts +5 -0
- package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
- package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
- package/dist/lib/dom/ssr/routes.d.ts +32 -0
- package/dist/lib/dom/ssr/server.d.ts +16 -0
- package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
- package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
- package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
- package/dist/lib/dom-export.d.ts +3 -0
- package/dist/lib/hooks.d.ts +286 -57
- package/dist/lib/router/history.d.ts +253 -0
- package/dist/lib/router/links.d.ts +104 -0
- package/dist/lib/router/router.d.ts +540 -0
- package/dist/lib/router/utils.d.ts +505 -0
- package/dist/lib/server-runtime/build.d.ts +38 -0
- package/dist/lib/server-runtime/cookies.d.ts +62 -0
- package/dist/lib/server-runtime/crypto.d.ts +2 -0
- package/dist/lib/server-runtime/data.d.ts +15 -0
- package/dist/lib/server-runtime/dev.d.ts +8 -0
- package/dist/lib/server-runtime/entry.d.ts +3 -0
- package/dist/lib/server-runtime/errors.d.ts +51 -0
- package/dist/lib/server-runtime/headers.d.ts +3 -0
- package/dist/lib/server-runtime/invariant.d.ts +2 -0
- package/dist/lib/server-runtime/jsonify.d.ts +33 -0
- package/dist/lib/server-runtime/markup.d.ts +1 -0
- package/dist/lib/server-runtime/mode.d.ts +9 -0
- package/dist/lib/server-runtime/responses.d.ts +37 -0
- package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
- package/dist/lib/server-runtime/routeModules.d.ts +212 -0
- package/dist/lib/server-runtime/routes.d.ts +31 -0
- package/dist/lib/server-runtime/server.d.ts +5 -0
- package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
- package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
- package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
- package/dist/lib/server-runtime/sessions.d.ts +140 -0
- package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
- package/dist/lib/server-runtime/typecheck.d.ts +4 -0
- package/dist/lib/server-runtime/warnings.d.ts +1 -0
- package/dist/lib/types.d.ts +71 -0
- package/dist/lib/types.mjs +10 -0
- package/dist/main-dom-export.js +19 -0
- package/dist/main.js +1 -1
- package/dist/react-router-dom.development.js +199 -0
- package/dist/react-router-dom.development.js.map +1 -0
- package/dist/react-router-dom.production.min.js +12 -0
- package/dist/react-router-dom.production.min.js.map +1 -0
- package/dist/react-router.development.js +12271 -1129
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router-dom.development.js +241 -0
- package/dist/umd/react-router-dom.development.js.map +1 -0
- package/dist/umd/react-router-dom.production.min.js +12 -0
- package/dist/umd/react-router-dom.production.min.js.map +1 -0
- package/dist/umd/react-router.development.js +12459 -1224
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +35 -6
- package/dist/index.js +0 -1467
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import type { History, Location, Path, To } from "./history";
|
|
2
|
+
import { Action as NavigationType } from "./history";
|
|
3
|
+
import type { AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteObject, DataStrategyFunction, FormEncType, HTMLFormMethod, MapRoutePropertiesFunction, RouteData, Submission, UIMatch, AgnosticPatchRoutesOnNavigationFunction, DataWithResponseInit } from "./utils";
|
|
4
|
+
/**
|
|
5
|
+
* A Router instance manages all navigation and data loading/mutations
|
|
6
|
+
*/
|
|
7
|
+
export interface Router {
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* PRIVATE - DO NOT USE
|
|
11
|
+
*
|
|
12
|
+
* Return the basename for the router
|
|
13
|
+
*/
|
|
14
|
+
get basename(): RouterInit["basename"];
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
* PRIVATE - DO NOT USE
|
|
18
|
+
*
|
|
19
|
+
* Return the future config for the router
|
|
20
|
+
*/
|
|
21
|
+
get future(): FutureConfig;
|
|
22
|
+
/**
|
|
23
|
+
* @private
|
|
24
|
+
* PRIVATE - DO NOT USE
|
|
25
|
+
*
|
|
26
|
+
* Return the current state of the router
|
|
27
|
+
*/
|
|
28
|
+
get state(): RouterState;
|
|
29
|
+
/**
|
|
30
|
+
* @private
|
|
31
|
+
* PRIVATE - DO NOT USE
|
|
32
|
+
*
|
|
33
|
+
* Return the routes for this router instance
|
|
34
|
+
*/
|
|
35
|
+
get routes(): AgnosticDataRouteObject[];
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
* PRIVATE - DO NOT USE
|
|
39
|
+
*
|
|
40
|
+
* Return the window associated with the router
|
|
41
|
+
*/
|
|
42
|
+
get window(): RouterInit["window"];
|
|
43
|
+
/**
|
|
44
|
+
* @private
|
|
45
|
+
* PRIVATE - DO NOT USE
|
|
46
|
+
*
|
|
47
|
+
* Initialize the router, including adding history listeners and kicking off
|
|
48
|
+
* initial data fetches. Returns a function to cleanup listeners and abort
|
|
49
|
+
* any in-progress loads
|
|
50
|
+
*/
|
|
51
|
+
initialize(): Router;
|
|
52
|
+
/**
|
|
53
|
+
* @private
|
|
54
|
+
* PRIVATE - DO NOT USE
|
|
55
|
+
*
|
|
56
|
+
* Subscribe to router.state updates
|
|
57
|
+
*
|
|
58
|
+
* @param fn function to call with the new state
|
|
59
|
+
*/
|
|
60
|
+
subscribe(fn: RouterSubscriber): () => void;
|
|
61
|
+
/**
|
|
62
|
+
* @private
|
|
63
|
+
* PRIVATE - DO NOT USE
|
|
64
|
+
*
|
|
65
|
+
* Enable scroll restoration behavior in the router
|
|
66
|
+
*
|
|
67
|
+
* @param savedScrollPositions Object that will manage positions, in case
|
|
68
|
+
* it's being restored from sessionStorage
|
|
69
|
+
* @param getScrollPosition Function to get the active Y scroll position
|
|
70
|
+
* @param getKey Function to get the key to use for restoration
|
|
71
|
+
*/
|
|
72
|
+
enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
|
|
73
|
+
/**
|
|
74
|
+
* @private
|
|
75
|
+
* PRIVATE - DO NOT USE
|
|
76
|
+
*
|
|
77
|
+
* Navigate forward/backward in the history stack
|
|
78
|
+
* @param to Delta to move in the history stack
|
|
79
|
+
*/
|
|
80
|
+
navigate(to: number): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Navigate to the given path
|
|
83
|
+
* @param to Path to navigate to
|
|
84
|
+
* @param opts Navigation options (method, submission, etc.)
|
|
85
|
+
*/
|
|
86
|
+
navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* @private
|
|
89
|
+
* PRIVATE - DO NOT USE
|
|
90
|
+
*
|
|
91
|
+
* Trigger a fetcher load/submission
|
|
92
|
+
*
|
|
93
|
+
* @param key Fetcher key
|
|
94
|
+
* @param routeId Route that owns the fetcher
|
|
95
|
+
* @param href href to fetch
|
|
96
|
+
* @param opts Fetcher options, (method, submission, etc.)
|
|
97
|
+
*/
|
|
98
|
+
fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* @private
|
|
101
|
+
* PRIVATE - DO NOT USE
|
|
102
|
+
*
|
|
103
|
+
* Trigger a revalidation of all current route loaders and fetcher loads
|
|
104
|
+
*/
|
|
105
|
+
revalidate(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* @private
|
|
108
|
+
* PRIVATE - DO NOT USE
|
|
109
|
+
*
|
|
110
|
+
* Utility function to create an href for the given location
|
|
111
|
+
* @param location
|
|
112
|
+
*/
|
|
113
|
+
createHref(location: Location | URL): string;
|
|
114
|
+
/**
|
|
115
|
+
* @private
|
|
116
|
+
* PRIVATE - DO NOT USE
|
|
117
|
+
*
|
|
118
|
+
* Utility function to URL encode a destination path according to the internal
|
|
119
|
+
* history implementation
|
|
120
|
+
* @param to
|
|
121
|
+
*/
|
|
122
|
+
encodeLocation(to: To): Path;
|
|
123
|
+
/**
|
|
124
|
+
* @private
|
|
125
|
+
* PRIVATE - DO NOT USE
|
|
126
|
+
*
|
|
127
|
+
* Get/create a fetcher for the given key
|
|
128
|
+
* @param key
|
|
129
|
+
*/
|
|
130
|
+
getFetcher<TData = any>(key: string): Fetcher<TData>;
|
|
131
|
+
/**
|
|
132
|
+
* @private
|
|
133
|
+
* PRIVATE - DO NOT USE
|
|
134
|
+
*
|
|
135
|
+
* Delete the fetcher for a given key
|
|
136
|
+
* @param key
|
|
137
|
+
*/
|
|
138
|
+
deleteFetcher(key: string): void;
|
|
139
|
+
/**
|
|
140
|
+
* @private
|
|
141
|
+
* PRIVATE - DO NOT USE
|
|
142
|
+
*
|
|
143
|
+
* Cleanup listeners and abort any in-progress loads
|
|
144
|
+
*/
|
|
145
|
+
dispose(): void;
|
|
146
|
+
/**
|
|
147
|
+
* @private
|
|
148
|
+
* PRIVATE - DO NOT USE
|
|
149
|
+
*
|
|
150
|
+
* Get a navigation blocker
|
|
151
|
+
* @param key The identifier for the blocker
|
|
152
|
+
* @param fn The blocker function implementation
|
|
153
|
+
*/
|
|
154
|
+
getBlocker(key: string, fn: BlockerFunction): Blocker;
|
|
155
|
+
/**
|
|
156
|
+
* @private
|
|
157
|
+
* PRIVATE - DO NOT USE
|
|
158
|
+
*
|
|
159
|
+
* Delete a navigation blocker
|
|
160
|
+
* @param key The identifier for the blocker
|
|
161
|
+
*/
|
|
162
|
+
deleteBlocker(key: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* @private
|
|
165
|
+
* PRIVATE DO NOT USE
|
|
166
|
+
*
|
|
167
|
+
* Patch additional children routes into an existing parent route
|
|
168
|
+
* @param routeId The parent route id or a callback function accepting `patch`
|
|
169
|
+
* to perform batch patching
|
|
170
|
+
* @param children The additional children routes
|
|
171
|
+
*/
|
|
172
|
+
patchRoutes(routeId: string | null, children: AgnosticRouteObject[]): void;
|
|
173
|
+
/**
|
|
174
|
+
* @private
|
|
175
|
+
* PRIVATE - DO NOT USE
|
|
176
|
+
*
|
|
177
|
+
* HMR needs to pass in-flight route updates to React Router
|
|
178
|
+
* TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
|
|
179
|
+
*/
|
|
180
|
+
_internalSetRoutes(routes: AgnosticRouteObject[]): void;
|
|
181
|
+
/**
|
|
182
|
+
* @private
|
|
183
|
+
* PRIVATE - DO NOT USE
|
|
184
|
+
*
|
|
185
|
+
* Internal fetch AbortControllers accessed by unit tests
|
|
186
|
+
*/
|
|
187
|
+
_internalFetchControllers: Map<string, AbortController>;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* State maintained internally by the router. During a navigation, all states
|
|
191
|
+
* reflect the the "old" location unless otherwise noted.
|
|
192
|
+
*/
|
|
193
|
+
export interface RouterState {
|
|
194
|
+
/**
|
|
195
|
+
* The action of the most recent navigation
|
|
196
|
+
*/
|
|
197
|
+
historyAction: NavigationType;
|
|
198
|
+
/**
|
|
199
|
+
* The current location reflected by the router
|
|
200
|
+
*/
|
|
201
|
+
location: Location;
|
|
202
|
+
/**
|
|
203
|
+
* The current set of route matches
|
|
204
|
+
*/
|
|
205
|
+
matches: AgnosticDataRouteMatch[];
|
|
206
|
+
/**
|
|
207
|
+
* Tracks whether we've completed our initial data load
|
|
208
|
+
*/
|
|
209
|
+
initialized: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Current scroll position we should start at for a new view
|
|
212
|
+
* - number -> scroll position to restore to
|
|
213
|
+
* - false -> do not restore scroll at all (used during submissions)
|
|
214
|
+
* - null -> don't have a saved position, scroll to hash or top of page
|
|
215
|
+
*/
|
|
216
|
+
restoreScrollPosition: number | false | null;
|
|
217
|
+
/**
|
|
218
|
+
* Indicate whether this navigation should skip resetting the scroll position
|
|
219
|
+
* if we are unable to restore the scroll position
|
|
220
|
+
*/
|
|
221
|
+
preventScrollReset: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Tracks the state of the current navigation
|
|
224
|
+
*/
|
|
225
|
+
navigation: Navigation;
|
|
226
|
+
/**
|
|
227
|
+
* Tracks any in-progress revalidations
|
|
228
|
+
*/
|
|
229
|
+
revalidation: RevalidationState;
|
|
230
|
+
/**
|
|
231
|
+
* Data from the loaders for the current matches
|
|
232
|
+
*/
|
|
233
|
+
loaderData: RouteData;
|
|
234
|
+
/**
|
|
235
|
+
* Data from the action for the current matches
|
|
236
|
+
*/
|
|
237
|
+
actionData: RouteData | null;
|
|
238
|
+
/**
|
|
239
|
+
* Errors caught from loaders for the current matches
|
|
240
|
+
*/
|
|
241
|
+
errors: RouteData | null;
|
|
242
|
+
/**
|
|
243
|
+
* Map of current fetchers
|
|
244
|
+
*/
|
|
245
|
+
fetchers: Map<string, Fetcher>;
|
|
246
|
+
/**
|
|
247
|
+
* Map of current blockers
|
|
248
|
+
*/
|
|
249
|
+
blockers: Map<string, Blocker>;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Data that can be passed into hydrate a Router from SSR
|
|
253
|
+
*/
|
|
254
|
+
export type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
|
|
255
|
+
/**
|
|
256
|
+
* Future flags to toggle new feature behavior
|
|
257
|
+
*/
|
|
258
|
+
export interface FutureConfig {
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Initialization options for createRouter
|
|
262
|
+
*/
|
|
263
|
+
export interface RouterInit {
|
|
264
|
+
routes: AgnosticRouteObject[];
|
|
265
|
+
history: History;
|
|
266
|
+
basename?: string;
|
|
267
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
268
|
+
future?: Partial<FutureConfig>;
|
|
269
|
+
hydrationData?: HydrationState;
|
|
270
|
+
window?: Window;
|
|
271
|
+
dataStrategy?: DataStrategyFunction;
|
|
272
|
+
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* State returned from a server-side query() call
|
|
276
|
+
*/
|
|
277
|
+
export interface StaticHandlerContext {
|
|
278
|
+
basename: Router["basename"];
|
|
279
|
+
location: RouterState["location"];
|
|
280
|
+
matches: RouterState["matches"];
|
|
281
|
+
loaderData: RouterState["loaderData"];
|
|
282
|
+
actionData: RouterState["actionData"];
|
|
283
|
+
errors: RouterState["errors"];
|
|
284
|
+
statusCode: number;
|
|
285
|
+
loaderHeaders: Record<string, Headers>;
|
|
286
|
+
actionHeaders: Record<string, Headers>;
|
|
287
|
+
_deepestRenderedBoundaryId?: string | null;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A StaticHandler instance manages a singular SSR navigation/fetch event
|
|
291
|
+
*/
|
|
292
|
+
export interface StaticHandler {
|
|
293
|
+
dataRoutes: AgnosticDataRouteObject[];
|
|
294
|
+
query(request: Request, opts?: {
|
|
295
|
+
requestContext?: unknown;
|
|
296
|
+
skipLoaderErrorBubbling?: boolean;
|
|
297
|
+
dataStrategy?: DataStrategyFunction;
|
|
298
|
+
}): Promise<StaticHandlerContext | Response>;
|
|
299
|
+
queryRoute(request: Request, opts?: {
|
|
300
|
+
routeId?: string;
|
|
301
|
+
requestContext?: unknown;
|
|
302
|
+
dataStrategy?: DataStrategyFunction;
|
|
303
|
+
}): Promise<any>;
|
|
304
|
+
}
|
|
305
|
+
type ViewTransitionOpts = {
|
|
306
|
+
currentLocation: Location;
|
|
307
|
+
nextLocation: Location;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* Subscriber function signature for changes to router state
|
|
311
|
+
*/
|
|
312
|
+
export interface RouterSubscriber {
|
|
313
|
+
(state: RouterState, opts: {
|
|
314
|
+
deletedFetchers: string[];
|
|
315
|
+
viewTransitionOpts?: ViewTransitionOpts;
|
|
316
|
+
flushSync: boolean;
|
|
317
|
+
}): void;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Function signature for determining the key to be used in scroll restoration
|
|
321
|
+
* for a given location
|
|
322
|
+
*/
|
|
323
|
+
export interface GetScrollRestorationKeyFunction {
|
|
324
|
+
(location: Location, matches: UIMatch[]): string | null;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Function signature for determining the current scroll position
|
|
328
|
+
*/
|
|
329
|
+
export interface GetScrollPositionFunction {
|
|
330
|
+
(): number;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
- "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.
|
|
334
|
+
- "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.
|
|
335
|
+
*/
|
|
336
|
+
export type RelativeRoutingType = "route" | "path";
|
|
337
|
+
type BaseNavigateOrFetchOptions = {
|
|
338
|
+
preventScrollReset?: boolean;
|
|
339
|
+
relative?: RelativeRoutingType;
|
|
340
|
+
flushSync?: boolean;
|
|
341
|
+
};
|
|
342
|
+
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
343
|
+
replace?: boolean;
|
|
344
|
+
state?: any;
|
|
345
|
+
fromRouteId?: string;
|
|
346
|
+
viewTransition?: boolean;
|
|
347
|
+
};
|
|
348
|
+
type BaseSubmissionOptions = {
|
|
349
|
+
formMethod?: HTMLFormMethod;
|
|
350
|
+
formEncType?: FormEncType;
|
|
351
|
+
} & ({
|
|
352
|
+
formData: FormData;
|
|
353
|
+
body?: undefined;
|
|
354
|
+
} | {
|
|
355
|
+
formData?: undefined;
|
|
356
|
+
body: any;
|
|
357
|
+
});
|
|
358
|
+
/**
|
|
359
|
+
* Options for a navigate() call for a normal (non-submission) navigation
|
|
360
|
+
*/
|
|
361
|
+
type LinkNavigateOptions = BaseNavigateOptions;
|
|
362
|
+
/**
|
|
363
|
+
* Options for a navigate() call for a submission navigation
|
|
364
|
+
*/
|
|
365
|
+
type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
|
|
366
|
+
/**
|
|
367
|
+
* Options to pass to navigate() for a navigation
|
|
368
|
+
*/
|
|
369
|
+
export type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
|
|
370
|
+
/**
|
|
371
|
+
* Options for a fetch() load
|
|
372
|
+
*/
|
|
373
|
+
type LoadFetchOptions = BaseNavigateOrFetchOptions;
|
|
374
|
+
/**
|
|
375
|
+
* Options for a fetch() submission
|
|
376
|
+
*/
|
|
377
|
+
type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
|
|
378
|
+
/**
|
|
379
|
+
* Options to pass to fetch()
|
|
380
|
+
*/
|
|
381
|
+
export type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
|
|
382
|
+
/**
|
|
383
|
+
* Potential states for state.navigation
|
|
384
|
+
*/
|
|
385
|
+
export type NavigationStates = {
|
|
386
|
+
Idle: {
|
|
387
|
+
state: "idle";
|
|
388
|
+
location: undefined;
|
|
389
|
+
formMethod: undefined;
|
|
390
|
+
formAction: undefined;
|
|
391
|
+
formEncType: undefined;
|
|
392
|
+
formData: undefined;
|
|
393
|
+
json: undefined;
|
|
394
|
+
text: undefined;
|
|
395
|
+
};
|
|
396
|
+
Loading: {
|
|
397
|
+
state: "loading";
|
|
398
|
+
location: Location;
|
|
399
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
400
|
+
formAction: Submission["formAction"] | undefined;
|
|
401
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
402
|
+
formData: Submission["formData"] | undefined;
|
|
403
|
+
json: Submission["json"] | undefined;
|
|
404
|
+
text: Submission["text"] | undefined;
|
|
405
|
+
};
|
|
406
|
+
Submitting: {
|
|
407
|
+
state: "submitting";
|
|
408
|
+
location: Location;
|
|
409
|
+
formMethod: Submission["formMethod"];
|
|
410
|
+
formAction: Submission["formAction"];
|
|
411
|
+
formEncType: Submission["formEncType"];
|
|
412
|
+
formData: Submission["formData"];
|
|
413
|
+
json: Submission["json"];
|
|
414
|
+
text: Submission["text"];
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
export type Navigation = NavigationStates[keyof NavigationStates];
|
|
418
|
+
export type RevalidationState = "idle" | "loading";
|
|
419
|
+
/**
|
|
420
|
+
* Potential states for fetchers
|
|
421
|
+
*/
|
|
422
|
+
export type FetcherStates<TData = any> = {
|
|
423
|
+
/**
|
|
424
|
+
* The fetcher is not calling a loader or action
|
|
425
|
+
*
|
|
426
|
+
* ```tsx
|
|
427
|
+
* fetcher.state === "idle"
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
Idle: {
|
|
431
|
+
state: "idle";
|
|
432
|
+
formMethod: undefined;
|
|
433
|
+
formAction: undefined;
|
|
434
|
+
formEncType: undefined;
|
|
435
|
+
text: undefined;
|
|
436
|
+
formData: undefined;
|
|
437
|
+
json: undefined;
|
|
438
|
+
/**
|
|
439
|
+
* If the fetcher has never been called, this will be undefined.
|
|
440
|
+
*/
|
|
441
|
+
data: TData | undefined;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* The fetcher is loading data from a {@link LoaderFunction | loader} from a
|
|
445
|
+
* call to {@link FetcherWithComponents.load | `fetcher.load`}.
|
|
446
|
+
*
|
|
447
|
+
* ```tsx
|
|
448
|
+
* // somewhere
|
|
449
|
+
* <button onClick={() => fetcher.load("/some/route") }>Load</button>
|
|
450
|
+
*
|
|
451
|
+
* // the state will update
|
|
452
|
+
* fetcher.state === "loading"
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
Loading: {
|
|
456
|
+
state: "loading";
|
|
457
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
458
|
+
formAction: Submission["formAction"] | undefined;
|
|
459
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
460
|
+
text: Submission["text"] | undefined;
|
|
461
|
+
formData: Submission["formData"] | undefined;
|
|
462
|
+
json: Submission["json"] | undefined;
|
|
463
|
+
data: TData | undefined;
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
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`}.
|
|
467
|
+
|
|
468
|
+
```tsx
|
|
469
|
+
// somewhere
|
|
470
|
+
<input
|
|
471
|
+
onChange={e => {
|
|
472
|
+
fetcher.submit(event.currentTarget.form, { method: "post" });
|
|
473
|
+
}}
|
|
474
|
+
/>
|
|
475
|
+
|
|
476
|
+
// the state will update
|
|
477
|
+
fetcher.state === "submitting"
|
|
478
|
+
|
|
479
|
+
// and formData will be available
|
|
480
|
+
fetcher.formData
|
|
481
|
+
```
|
|
482
|
+
*/
|
|
483
|
+
Submitting: {
|
|
484
|
+
state: "submitting";
|
|
485
|
+
formMethod: Submission["formMethod"];
|
|
486
|
+
formAction: Submission["formAction"];
|
|
487
|
+
formEncType: Submission["formEncType"];
|
|
488
|
+
text: Submission["text"];
|
|
489
|
+
formData: Submission["formData"];
|
|
490
|
+
json: Submission["json"];
|
|
491
|
+
data: TData | undefined;
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
export type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
|
|
495
|
+
interface BlockerBlocked {
|
|
496
|
+
state: "blocked";
|
|
497
|
+
reset(): void;
|
|
498
|
+
proceed(): void;
|
|
499
|
+
location: Location;
|
|
500
|
+
}
|
|
501
|
+
interface BlockerUnblocked {
|
|
502
|
+
state: "unblocked";
|
|
503
|
+
reset: undefined;
|
|
504
|
+
proceed: undefined;
|
|
505
|
+
location: undefined;
|
|
506
|
+
}
|
|
507
|
+
interface BlockerProceeding {
|
|
508
|
+
state: "proceeding";
|
|
509
|
+
reset: undefined;
|
|
510
|
+
proceed: undefined;
|
|
511
|
+
location: Location;
|
|
512
|
+
}
|
|
513
|
+
export type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
|
|
514
|
+
export type BlockerFunction = (args: {
|
|
515
|
+
currentLocation: Location;
|
|
516
|
+
nextLocation: Location;
|
|
517
|
+
historyAction: NavigationType;
|
|
518
|
+
}) => boolean;
|
|
519
|
+
export declare const IDLE_NAVIGATION: NavigationStates["Idle"];
|
|
520
|
+
export declare const IDLE_FETCHER: FetcherStates["Idle"];
|
|
521
|
+
export declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
522
|
+
/**
|
|
523
|
+
* Create a router and listen to history POP navigations
|
|
524
|
+
*/
|
|
525
|
+
export declare function createRouter(init: RouterInit): Router;
|
|
526
|
+
export interface CreateStaticHandlerOptions {
|
|
527
|
+
basename?: string;
|
|
528
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
529
|
+
future?: {};
|
|
530
|
+
}
|
|
531
|
+
export declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
|
|
532
|
+
/**
|
|
533
|
+
* Given an existing StaticHandlerContext and an error thrown at render time,
|
|
534
|
+
* provide an updated StaticHandlerContext suitable for a second SSR render
|
|
535
|
+
*
|
|
536
|
+
* @category Utils
|
|
537
|
+
*/
|
|
538
|
+
export declare function getStaticContextFromError(routes: AgnosticDataRouteObject[], context: StaticHandlerContext, error: any): StaticHandlerContext;
|
|
539
|
+
export declare function isDataWithResponseInit(value: any): value is DataWithResponseInit<unknown>;
|
|
540
|
+
export {};
|