react-router 0.0.0-experimental-e56aa53bc → 0.0.0-experimental-e6fb6e074

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 (65) hide show
  1. package/CHANGELOG.md +18 -734
  2. package/README.md +14 -5
  3. package/dist/index.d.ts +30 -0
  4. package/dist/index.js +1501 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/components.d.ts +157 -0
  7. package/dist/lib/context.d.ts +102 -0
  8. package/dist/lib/deprecations.d.ts +4 -0
  9. package/dist/lib/hooks.d.ts +181 -0
  10. package/dist/main.js +19 -0
  11. package/dist/react-router.development.js +1397 -0
  12. package/dist/react-router.development.js.map +1 -0
  13. package/dist/react-router.production.min.js +12 -0
  14. package/dist/react-router.production.min.js.map +1 -0
  15. package/dist/umd/react-router.development.js +1624 -0
  16. package/dist/umd/react-router.development.js.map +1 -0
  17. package/dist/umd/react-router.production.min.js +12 -0
  18. package/dist/umd/react-router.production.min.js.map +1 -0
  19. package/package.json +9 -111
  20. package/dist/development/chunk-RMWJZNG5.mjs +0 -11505
  21. package/dist/development/data-CQbyyGzl.d.mts +0 -11
  22. package/dist/development/data-CQbyyGzl.d.ts +0 -11
  23. package/dist/development/dom-export.d.mts +0 -23
  24. package/dist/development/dom-export.d.ts +0 -23
  25. package/dist/development/dom-export.js +0 -6341
  26. package/dist/development/dom-export.mjs +0 -222
  27. package/dist/development/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  28. package/dist/development/fog-of-war-DrUCUQQ-.d.ts +0 -1778
  29. package/dist/development/index.d.mts +0 -855
  30. package/dist/development/index.d.ts +0 -855
  31. package/dist/development/index.js +0 -11664
  32. package/dist/development/index.mjs +0 -263
  33. package/dist/development/lib/types/route-module.d.mts +0 -209
  34. package/dist/development/lib/types/route-module.d.ts +0 -209
  35. package/dist/development/lib/types/route-module.js +0 -28
  36. package/dist/development/lib/types/route-module.mjs +0 -10
  37. package/dist/development/route-data-BIYebJr3.d.mts +0 -1749
  38. package/dist/development/route-data-BIYebJr3.d.ts +0 -1749
  39. package/dist/development/rsc-export.d.mts +0 -1788
  40. package/dist/development/rsc-export.d.ts +0 -1788
  41. package/dist/development/rsc-export.js +0 -2778
  42. package/dist/development/rsc-export.mjs +0 -2743
  43. package/dist/production/chunk-BXBFRMFA.mjs +0 -11505
  44. package/dist/production/data-CQbyyGzl.d.mts +0 -11
  45. package/dist/production/data-CQbyyGzl.d.ts +0 -11
  46. package/dist/production/dom-export.d.mts +0 -23
  47. package/dist/production/dom-export.d.ts +0 -23
  48. package/dist/production/dom-export.js +0 -6341
  49. package/dist/production/dom-export.mjs +0 -222
  50. package/dist/production/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  51. package/dist/production/fog-of-war-DrUCUQQ-.d.ts +0 -1778
  52. package/dist/production/index.d.mts +0 -855
  53. package/dist/production/index.d.ts +0 -855
  54. package/dist/production/index.js +0 -11664
  55. package/dist/production/index.mjs +0 -263
  56. package/dist/production/lib/types/route-module.d.mts +0 -209
  57. package/dist/production/lib/types/route-module.d.ts +0 -209
  58. package/dist/production/lib/types/route-module.js +0 -28
  59. package/dist/production/lib/types/route-module.mjs +0 -10
  60. package/dist/production/route-data-BIYebJr3.d.mts +0 -1749
  61. package/dist/production/route-data-BIYebJr3.d.ts +0 -1749
  62. package/dist/production/rsc-export.d.mts +0 -1788
  63. package/dist/production/rsc-export.d.ts +0 -1788
  64. package/dist/production/rsc-export.js +0 -2778
  65. package/dist/production/rsc-export.mjs +0 -2743
@@ -1,855 +0,0 @@
1
- import { a as Router, b as RouteModules, D as DataStrategyFunction, c as RouteManifest, S as ServerRouteModule, M as MiddlewareEnabled, u as unstable_RouterContextProvider, L as LoaderFunctionArgs, A as ActionFunctionArgs, T as To, d as RelativeRoutingType, e as Location, f as Action, P as ParamParseKey, g as Path, h as PathPattern, i as PathMatch, N as NavigateOptions, j as Params$1, k as RouteObject, l as Navigation, m as RevalidationState, U as UIMatch, n as SerializeFrom, B as BlockerFunction, o as Blocker, p as StaticHandlerContext, q as StaticHandler, F as FutureConfig$1, C as CreateStaticHandlerOptions$1, I as InitialEntry, H as HydrationState, r as unstable_InitialContext, s as IndexRouteObject, t as LoaderFunction, v as ActionFunction, w as MetaFunction, x as LinksFunction, y as NonIndexRouteObject, E as Equal, z as RouterState, G as DataRouteObject, J as ClientLoaderFunction } from './route-data-BIYebJr3.mjs';
2
- export { aw as ClientActionFunction, ax as ClientActionFunctionArgs, ay as ClientLoaderFunctionArgs, ar as DataRouteMatch, Z as DataStrategyFunctionArgs, _ as DataStrategyMatch, $ as DataStrategyResult, a1 as ErrorResponse, Q as Fetcher, a2 as FormEncType, a3 as FormMethod, aG as Future, K as GetScrollPositionFunction, O as GetScrollRestorationKeyFunction, a4 as HTMLFormMethod, az as HeadersArgs, aA as HeadersFunction, aE as HtmlLinkDescriptor, ah as IDLE_BLOCKER, ag as IDLE_FETCHER, af as IDLE_NAVIGATION, a5 as LazyRouteFunction, aF as LinkDescriptor, aB as MetaArgs, aC as MetaDescriptor, V as NavigationStates, as as Navigator, aD as PageLinkDescriptor, at as PatchRoutesOnNavigationFunction, au as PatchRoutesOnNavigationFunctionArgs, a7 as PathParam, a8 as RedirectFunction, av as RouteMatch, Y as RouterFetchOptions, R as RouterInit, X as RouterNavigateOptions, W as RouterSubscriber, aa as ShouldRevalidateFunction, ab as ShouldRevalidateFunctionArgs, aM as UNSAFE_DataRouterContext, aN as UNSAFE_DataRouterStateContext, a0 as UNSAFE_DataWithResponseInit, aL as UNSAFE_ErrorResponseImpl, aO as UNSAFE_FetchersContext, aP as UNSAFE_LocationContext, aQ as UNSAFE_NavigationContext, aR as UNSAFE_RouteContext, aS as UNSAFE_ViewTransitionContext, aI as UNSAFE_createBrowserHistory, aK as UNSAFE_createRouter, aJ as UNSAFE_invariant, ad as createPath, ai as data, aj as generatePath, ak as isRouteErrorResponse, al as matchPath, am as matchRoutes, ae as parsePath, an as redirect, ao as redirectDocument, ap as replace, aq as resolvePath, a6 as unstable_MiddlewareFunction, a9 as unstable_RouterContext, aH as unstable_SerializesTo, ac as unstable_createContext } from './route-data-BIYebJr3.mjs';
3
- import { A as AssetsManifest, a as Route, F as FutureConfig, E as EntryContext, C as CriticalCss, S as ServerPayload } from './fog-of-war-C5L_Yd5M.mjs';
4
- export { g as Await, b as AwaitProps, U as BrowserRouter, B as BrowserRouterProps, D as DOMRouterOpts, aj as DecodeServerResponseFunction, ak as EncodeActionFunction, w as FetcherFormProps, J as FetcherSubmitFunction, a8 as FetcherSubmitOptions, K as FetcherWithComponents, Z as Form, x as FormProps, V as HashRouter, H as HashRouterProps, s as HistoryRouterProps, I as IndexRouteProps, L as LayoutRouteProps, W as Link, t as LinkProps, af as Links, h as MemoryRouter, M as MemoryRouterOpts, c as MemoryRouterProps, ae as Meta, Y as NavLink, u as NavLinkProps, v as NavLinkRenderProps, i as Navigate, N as NavigateProps, j as Outlet, O as OutletProps, a9 as ParamKeyValuePair, P as PathRouteProps, ah as PrefetchPageLinks, am as RSCHydratedRouter, k as Route, d as RouteProps, l as Router, e as RouterProps, m as RouterProvider, R as RouterProviderProps, n as Routes, f as RoutesProps, ag as Scripts, ai as ScriptsProps, _ as ScrollRestoration, y as ScrollRestorationProps, z as SetURLSearchParams, G as SubmitFunction, aa as SubmitOptions, ac as SubmitTarget, at as UNSAFE_FrameworkContext, aq as UNSAFE_WithErrorBoundaryProps, ap as UNSAFE_WithHydrateFallbackProps, ao as UNSAFE_WithRouteComponentProps, aw as UNSAFE_createClientRoutes, ax as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, au as UNSAFE_getPatchRoutesOnNavigationFunction, ar as UNSAFE_hydrationRouteProperties, as as UNSAFE_mapRouteProperties, ay as UNSAFE_shouldHydrateRouteLoader, av as UNSAFE_useFogOFWarDiscovery, az as UNSAFE_useScrollRestoration, ab as URLSearchParamsInit, Q as createBrowserRouter, al as createCallServer, T as createHashRouter, o as createMemoryRouter, p as createRoutesFromChildren, q as createRoutesFromElements, ad as createSearchParams, an as getServerStream, r as renderMatches, X as unstable_HistoryRouter, a6 as unstable_usePrompt, a5 as useBeforeUnload, a3 as useFetcher, a4 as useFetchers, a2 as useFormAction, $ as useLinkClickHandler, a0 as useSearchParams, a1 as useSubmit, a7 as useViewTransitionState } from './fog-of-war-C5L_Yd5M.mjs';
5
- import * as React from 'react';
6
- import { ReactElement } from 'react';
7
- import { ParseOptions, SerializeOptions } from 'cookie';
8
- export { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions } from 'cookie';
9
- import { A as AppLoadContext } from './data-CQbyyGzl.mjs';
10
-
11
- declare const SingleFetchRedirectSymbol: unique symbol;
12
- declare function getTurboStreamSingleFetchDataStrategy(getRouter: () => Router, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, basename: string | undefined): DataStrategyFunction;
13
- declare function decodeViaTurboStream(body: ReadableStream<Uint8Array>, global: Window | typeof globalThis): Promise<{
14
- done: Promise<undefined>;
15
- value: unknown;
16
- }>;
17
-
18
- /**
19
- * The mode to use when running the server.
20
- */
21
- declare enum ServerMode {
22
- Development = "development",
23
- Production = "production",
24
- Test = "test"
25
- }
26
-
27
- type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
28
- interface ServerRoute extends Route {
29
- children: ServerRoute[];
30
- module: ServerRouteModule;
31
- }
32
-
33
- type OptionalCriticalCss = CriticalCss | undefined;
34
- /**
35
- * The output of the compiler for the server build.
36
- */
37
- interface ServerBuild {
38
- entry: {
39
- module: ServerEntryModule;
40
- };
41
- routes: ServerRouteManifest;
42
- assets: AssetsManifest;
43
- basename?: string;
44
- publicPath: string;
45
- assetsBuildDirectory: string;
46
- future: FutureConfig;
47
- ssr: boolean;
48
- unstable_getCriticalCss?: (args: {
49
- pathname: string;
50
- }) => OptionalCriticalCss | Promise<OptionalCriticalCss>;
51
- /**
52
- * @deprecated This is now done via a custom header during prerendering
53
- */
54
- isSpaMode: boolean;
55
- prerender: string[];
56
- }
57
- interface HandleDocumentRequestFunction {
58
- (request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: MiddlewareEnabled extends true ? unstable_RouterContextProvider : AppLoadContext): Promise<Response> | Response;
59
- }
60
- interface HandleDataRequestFunction {
61
- (response: Response, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<Response> | Response;
62
- }
63
- interface HandleErrorFunction {
64
- (error: unknown, args: LoaderFunctionArgs | ActionFunctionArgs): void;
65
- }
66
- /**
67
- * A module that serves as the entry point for a Remix app during server
68
- * rendering.
69
- */
70
- interface ServerEntryModule {
71
- default: HandleDocumentRequestFunction;
72
- handleDataRequest?: HandleDataRequestFunction;
73
- handleError?: HandleErrorFunction;
74
- streamTimeout?: number;
75
- }
76
-
77
- /**
78
- Resolves a URL against the current location.
79
-
80
- ```tsx
81
- import { useHref } from "react-router"
82
-
83
- function SomeComponent() {
84
- let href = useHref("some/where");
85
- // "/resolved/some/where"
86
- }
87
- ```
88
-
89
- @category Hooks
90
- */
91
- declare function useHref(to: To, { relative }?: {
92
- relative?: RelativeRoutingType;
93
- }): string;
94
- /**
95
- * Returns true if this component is a descendant of a Router, useful to ensure
96
- * a component is used within a Router.
97
- *
98
- * @category Hooks
99
- */
100
- declare function useInRouterContext(): boolean;
101
- /**
102
- Returns the current {@link Location}. This can be useful if you'd like to perform some side effect whenever it changes.
103
-
104
- ```tsx
105
- import * as React from 'react'
106
- import { useLocation } from 'react-router'
107
-
108
- function SomeComponent() {
109
- let location = useLocation()
110
-
111
- React.useEffect(() => {
112
- // Google Analytics
113
- ga('send', 'pageview')
114
- }, [location]);
115
-
116
- return (
117
- // ...
118
- );
119
- }
120
- ```
121
-
122
- @category Hooks
123
- */
124
- declare function useLocation(): Location;
125
- /**
126
- * Returns the current navigation action which describes how the router came to
127
- * the current location, either by a pop, push, or replace on the history stack.
128
- *
129
- * @category Hooks
130
- */
131
- declare function useNavigationType(): Action;
132
- /**
133
- * Returns a PathMatch object if the given pattern matches the current URL.
134
- * This is useful for components that need to know "active" state, e.g.
135
- * `<NavLink>`.
136
- *
137
- * @category Hooks
138
- */
139
- declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
140
- /**
141
- * The interface for the navigate() function returned from useNavigate().
142
- */
143
- interface NavigateFunction {
144
- (to: To, options?: NavigateOptions): void | Promise<void>;
145
- (delta: number): void | Promise<void>;
146
- }
147
- /**
148
- Returns a function that lets you navigate programmatically in the browser in response to user interactions or effects.
149
-
150
- ```tsx
151
- import { useNavigate } from "react-router";
152
-
153
- function SomeComponent() {
154
- let navigate = useNavigate();
155
- return (
156
- <button
157
- onClick={() => {
158
- navigate(-1);
159
- }}
160
- />
161
- );
162
- }
163
- ```
164
-
165
- It's often better to use {@link redirect} in {@link ActionFunction | actions} and {@link LoaderFunction | loaders} than this hook.
166
-
167
- @category Hooks
168
- */
169
- declare function useNavigate(): NavigateFunction;
170
- /**
171
- * Returns the parent route {@link OutletProps.context | `<Outlet context>`}.
172
- *
173
- * @category Hooks
174
- */
175
- declare function useOutletContext<Context = unknown>(): Context;
176
- /**
177
- * Returns the element for the child route at this level of the route
178
- * hierarchy. Used internally by `<Outlet>` to render child routes.
179
- *
180
- * @category Hooks
181
- */
182
- declare function useOutlet(context?: unknown): React.ReactElement | null;
183
- /**
184
- Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.
185
-
186
- ```tsx
187
- import { useParams } from "react-router"
188
-
189
- function SomeComponent() {
190
- let params = useParams()
191
- params.postId
192
- }
193
- ```
194
-
195
- Assuming a route pattern like `/posts/:postId` is matched by `/posts/123` then `params.postId` will be `"123"`.
196
-
197
- @category Hooks
198
- */
199
- declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
200
- ParamsOrKey
201
- ] extends [string] ? Params$1<ParamsOrKey> : Partial<ParamsOrKey>>;
202
- /**
203
- Resolves the pathname of the given `to` value against the current location. Similar to {@link useHref}, but returns a {@link Path} instead of a string.
204
-
205
- ```tsx
206
- import { useResolvedPath } from "react-router"
207
-
208
- function SomeComponent() {
209
- // if the user is at /dashboard/profile
210
- let path = useResolvedPath("../accounts")
211
- path.pathname // "/dashboard/accounts"
212
- path.search // ""
213
- path.hash // ""
214
- }
215
- ```
216
-
217
- @category Hooks
218
- */
219
- declare function useResolvedPath(to: To, { relative }?: {
220
- relative?: RelativeRoutingType;
221
- }): Path;
222
- /**
223
- Hook version of {@link Routes | `<Routes>`} that uses objects instead of components. These objects have the same properties as the component props.
224
-
225
- The return value of `useRoutes` is either a valid React element you can use to render the route tree, or `null` if nothing matched.
226
-
227
- ```tsx
228
- import * as React from "react";
229
- import { useRoutes } from "react-router";
230
-
231
- function App() {
232
- let element = useRoutes([
233
- {
234
- path: "/",
235
- element: <Dashboard />,
236
- children: [
237
- {
238
- path: "messages",
239
- element: <DashboardMessages />,
240
- },
241
- { path: "tasks", element: <DashboardTasks /> },
242
- ],
243
- },
244
- { path: "team", element: <AboutPage /> },
245
- ]);
246
-
247
- return element;
248
- }
249
- ```
250
-
251
- @category Hooks
252
- */
253
- declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
254
- /**
255
- Returns the current navigation, defaulting to an "idle" navigation when no navigation is in progress. You can use this to render pending UI (like a global spinner) or read FormData from a form navigation.
256
-
257
- ```tsx
258
- import { useNavigation } from "react-router"
259
-
260
- function SomeComponent() {
261
- let navigation = useNavigation();
262
- navigation.state
263
- navigation.formData
264
- // etc.
265
- }
266
- ```
267
-
268
- @category Hooks
269
- */
270
- declare function useNavigation(): Navigation;
271
- /**
272
- Revalidate the data on the page for reasons outside of normal data mutations like window focus or polling on an interval.
273
-
274
- ```tsx
275
- import { useRevalidator } from "react-router";
276
-
277
- function WindowFocusRevalidator() {
278
- const revalidator = useRevalidator();
279
-
280
- useFakeWindowFocus(() => {
281
- revalidator.revalidate();
282
- });
283
-
284
- return (
285
- <div hidden={revalidator.state === "idle"}>
286
- Revalidating...
287
- </div>
288
- );
289
- }
290
- ```
291
-
292
- Note that page data is already revalidated automatically after actions. If you find yourself using this for normal CRUD operations on your data in response to user interactions, you're probably not taking advantage of the other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do this automatically.
293
-
294
- @category Hooks
295
- */
296
- declare function useRevalidator(): {
297
- revalidate(): Promise<void>;
298
- state: RevalidationState;
299
- };
300
- /**
301
- * Returns the active route matches, useful for accessing loaderData for
302
- * parent/child routes or the route "handle" property
303
- *
304
- * @category Hooks
305
- */
306
- declare function useMatches(): UIMatch[];
307
- /**
308
- Returns the data from the closest route {@link LoaderFunction | loader} or {@link ClientLoaderFunction | client loader}.
309
-
310
- ```tsx
311
- import { useLoaderData } from "react-router"
312
-
313
- export async function loader() {
314
- return await fakeDb.invoices.findAll();
315
- }
316
-
317
- export default function Invoices() {
318
- let invoices = useLoaderData<typeof loader>();
319
- // ...
320
- }
321
- ```
322
-
323
- @category Hooks
324
- */
325
- declare function useLoaderData<T = any>(): SerializeFrom<T>;
326
- /**
327
- Returns the loader data for a given route by route ID.
328
-
329
- ```tsx
330
- import { useRouteLoaderData } from "react-router";
331
-
332
- function SomeComponent() {
333
- const { user } = useRouteLoaderData("root");
334
- }
335
- ```
336
-
337
- Route IDs are created automatically. They are simply the path of the route file relative to the app folder without the extension.
338
-
339
- | Route Filename | Route ID |
340
- | -------------------------- | -------------------- |
341
- | `app/root.tsx` | `"root"` |
342
- | `app/routes/teams.tsx` | `"routes/teams"` |
343
- | `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
344
-
345
- If you created an ID manually, you can use that instead:
346
-
347
- ```tsx
348
- route("/", "containers/app.tsx", { id: "app" }})
349
- ```
350
-
351
- @category Hooks
352
- */
353
- declare function useRouteLoaderData<T = any>(routeId: string): SerializeFrom<T> | undefined;
354
- /**
355
- Returns the action data from the most recent POST navigation form submission or `undefined` if there hasn't been one.
356
-
357
- ```tsx
358
- import { Form, useActionData } from "react-router"
359
-
360
- export async function action({ request }) {
361
- const body = await request.formData()
362
- const name = body.get("visitorsName")
363
- return { message: `Hello, ${name}` }
364
- }
365
-
366
- export default function Invoices() {
367
- const data = useActionData()
368
- return (
369
- <Form method="post">
370
- <input type="text" name="visitorsName" />
371
- {data ? data.message : "Waiting..."}
372
- </Form>
373
- )
374
- }
375
- ```
376
-
377
- @category Hooks
378
- */
379
- declare function useActionData<T = any>(): SerializeFrom<T> | undefined;
380
- /**
381
- Accesses the error thrown during an {@link ActionFunction | action}, {@link LoaderFunction | loader}, or component render to be used in a route module Error Boundary.
382
-
383
- ```tsx
384
- export function ErrorBoundary() {
385
- const error = useRouteError();
386
- return <div>{error.message}</div>;
387
- }
388
- ```
389
-
390
- @category Hooks
391
- */
392
- declare function useRouteError(): unknown;
393
- /**
394
- Returns the resolved promise value from the closest {@link Await | `<Await>`}.
395
-
396
- ```tsx
397
- function SomeDescendant() {
398
- const value = useAsyncValue();
399
- // ...
400
- }
401
-
402
- // somewhere in your app
403
- <Await resolve={somePromise}>
404
- <SomeDescendant />
405
- </Await>
406
- ```
407
-
408
- @category Hooks
409
- */
410
- declare function useAsyncValue(): unknown;
411
- /**
412
- Returns the rejection value from the closest {@link Await | `<Await>`}.
413
-
414
- ```tsx
415
- import { Await, useAsyncError } from "react-router"
416
-
417
- function ErrorElement() {
418
- const error = useAsyncError();
419
- return (
420
- <p>Uh Oh, something went wrong! {error.message}</p>
421
- );
422
- }
423
-
424
- // somewhere in your app
425
- <Await
426
- resolve={promiseThatRejects}
427
- errorElement={<ErrorElement />}
428
- />
429
- ```
430
-
431
- @category Hooks
432
- */
433
- declare function useAsyncError(): unknown;
434
- /**
435
- * Allow the application to block navigations within the SPA and present the
436
- * user a confirmation dialog to confirm the navigation. Mostly used to avoid
437
- * using half-filled form data. This does not handle hard-reloads or
438
- * cross-origin navigations.
439
- *
440
- * @category Hooks
441
- */
442
- declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
443
-
444
- interface StaticRouterProps {
445
- basename?: string;
446
- children?: React.ReactNode;
447
- location: Partial<Location> | string;
448
- }
449
- /**
450
- * A `<Router>` that may not navigate to any other location. This is useful
451
- * on the server where there is no stateful UI.
452
- *
453
- * @category Component Routers
454
- */
455
- declare function StaticRouter({ basename, children, location: locationProp, }: StaticRouterProps): React.JSX.Element;
456
- interface StaticRouterProviderProps {
457
- context: StaticHandlerContext;
458
- router: Router;
459
- hydrate?: boolean;
460
- nonce?: string;
461
- }
462
- /**
463
- * A Data Router that may not navigate to any other location. This is useful
464
- * on the server where there is no stateful UI.
465
- *
466
- * @category Component Routers
467
- */
468
- declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): React.JSX.Element;
469
- type CreateStaticHandlerOptions = Omit<CreateStaticHandlerOptions$1, "mapRouteProperties">;
470
- /**
471
- * @category Utils
472
- */
473
- declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
474
- /**
475
- * @category Data Routers
476
- */
477
- declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
478
- future?: Partial<FutureConfig$1>;
479
- }): Router;
480
-
481
- interface ServerRouterProps {
482
- context: EntryContext;
483
- url: string | URL;
484
- nonce?: string;
485
- }
486
- /**
487
- * The entry point for a Remix app when it is rendered on the server (in
488
- * `app/entry.server.js`). This component is used to generate the HTML in the
489
- * response from the server.
490
- *
491
- * @category Components
492
- */
493
- declare function ServerRouter({ context, url, nonce, }: ServerRouterProps): ReactElement;
494
-
495
- interface StubIndexRouteObject extends Omit<IndexRouteObject, "loader" | "action" | "element" | "errorElement" | "children"> {
496
- loader?: LoaderFunction;
497
- action?: ActionFunction;
498
- children?: StubRouteObject[];
499
- meta?: MetaFunction;
500
- links?: LinksFunction;
501
- }
502
- interface StubNonIndexRouteObject extends Omit<NonIndexRouteObject, "loader" | "action" | "element" | "errorElement" | "children"> {
503
- loader?: LoaderFunction;
504
- action?: ActionFunction;
505
- children?: StubRouteObject[];
506
- meta?: MetaFunction;
507
- links?: LinksFunction;
508
- }
509
- type StubRouteObject = StubIndexRouteObject | StubNonIndexRouteObject;
510
- interface RoutesTestStubProps {
511
- /**
512
- * The initial entries in the history stack. This allows you to start a test with
513
- * multiple locations already in the history stack (for testing a back navigation, etc.)
514
- * The test will default to the last entry in initialEntries if no initialIndex is provided.
515
- * e.g. initialEntries={["/home", "/about", "/contact"]}
516
- */
517
- initialEntries?: InitialEntry[];
518
- /**
519
- * The initial index in the history stack to render. This allows you to start a test at a specific entry.
520
- * It defaults to the last entry in initialEntries.
521
- * e.g.
522
- * initialEntries: ["/", "/events/123"]
523
- * initialIndex: 1 // start at "/events/123"
524
- */
525
- initialIndex?: number;
526
- /**
527
- * Used to set the route's initial loader and action data.
528
- * e.g. hydrationData={{
529
- * loaderData: { "/contact": { locale: "en-US" } },
530
- * actionData: { "/login": { errors: { email: "invalid email" } }}
531
- * }}
532
- */
533
- hydrationData?: HydrationState;
534
- /**
535
- * Future flags mimicking the settings in react-router.config.ts
536
- */
537
- future?: Partial<FutureConfig>;
538
- }
539
- /**
540
- * @category Utils
541
- */
542
- declare function createRoutesStub(routes: StubRouteObject[], unstable_getContext?: () => unstable_InitialContext): ({ initialEntries, initialIndex, hydrationData, future, }: RoutesTestStubProps) => React.JSX.Element;
543
-
544
- interface CookieSignatureOptions {
545
- /**
546
- * An array of secrets that may be used to sign/unsign the value of a cookie.
547
- *
548
- * The array makes it easy to rotate secrets. New secrets should be added to
549
- * the beginning of the array. `cookie.serialize()` will always use the first
550
- * value in the array, but `cookie.parse()` may use any of them so that
551
- * cookies that were signed with older secrets still work.
552
- */
553
- secrets?: string[];
554
- }
555
- type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
556
- /**
557
- * A HTTP cookie.
558
- *
559
- * A Cookie is a logical container for metadata about a HTTP cookie; its name
560
- * and options. But it doesn't contain a value. Instead, it has `parse()` and
561
- * `serialize()` methods that allow a single instance to be reused for
562
- * parsing/encoding multiple different values.
563
- *
564
- * @see https://remix.run/utils/cookies#cookie-api
565
- */
566
- interface Cookie {
567
- /**
568
- * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
569
- */
570
- readonly name: string;
571
- /**
572
- * True if this cookie uses one or more secrets for verification.
573
- */
574
- readonly isSigned: boolean;
575
- /**
576
- * The Date this cookie expires.
577
- *
578
- * Note: This is calculated at access time using `maxAge` when no `expires`
579
- * option is provided to `createCookie()`.
580
- */
581
- readonly expires?: Date;
582
- /**
583
- * Parses a raw `Cookie` header and returns the value of this cookie or
584
- * `null` if it's not present.
585
- */
586
- parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
587
- /**
588
- * Serializes the given value to a string and returns the `Set-Cookie`
589
- * header.
590
- */
591
- serialize(value: any, options?: SerializeOptions): Promise<string>;
592
- }
593
- /**
594
- * Creates a logical container for managing a browser cookie from the server.
595
- */
596
- declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
597
- type IsCookieFunction = (object: any) => object is Cookie;
598
- /**
599
- * Returns true if an object is a Remix cookie container.
600
- *
601
- * @see https://remix.run/utils/cookies#iscookie
602
- */
603
- declare const isCookie: IsCookieFunction;
604
-
605
- type RequestHandler = (request: Request, loadContext?: MiddlewareEnabled extends true ? unstable_InitialContext : AppLoadContext) => Promise<Response>;
606
- type CreateRequestHandlerFunction = (build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>), mode?: string) => RequestHandler;
607
- declare const createRequestHandler: CreateRequestHandlerFunction;
608
-
609
- /**
610
- * An object of name/value pairs to be used in the session.
611
- */
612
- interface SessionData {
613
- [name: string]: any;
614
- }
615
- /**
616
- * Session persists data across HTTP requests.
617
- *
618
- * @see https://remix.run/utils/sessions#session-api
619
- */
620
- interface Session<Data = SessionData, FlashData = Data> {
621
- /**
622
- * A unique identifier for this session.
623
- *
624
- * Note: This will be the empty string for newly created sessions and
625
- * sessions that are not backed by a database (i.e. cookie-based sessions).
626
- */
627
- readonly id: string;
628
- /**
629
- * The raw data contained in this session.
630
- *
631
- * This is useful mostly for SessionStorage internally to access the raw
632
- * session data to persist.
633
- */
634
- readonly data: FlashSessionData<Data, FlashData>;
635
- /**
636
- * Returns `true` if the session has a value for the given `name`, `false`
637
- * otherwise.
638
- */
639
- has(name: (keyof Data | keyof FlashData) & string): boolean;
640
- /**
641
- * Returns the value for the given `name` in this session.
642
- */
643
- get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
644
- /**
645
- * Sets a value in the session for the given `name`.
646
- */
647
- set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
648
- /**
649
- * Sets a value in the session that is only valid until the next `get()`.
650
- * This can be useful for temporary values, like error messages.
651
- */
652
- flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
653
- /**
654
- * Removes a value from the session.
655
- */
656
- unset(name: keyof Data & string): void;
657
- }
658
- type FlashSessionData<Data, FlashData> = Partial<Data & {
659
- [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
660
- }>;
661
- type FlashDataKey<Key extends string> = `__flash_${Key}__`;
662
- type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
663
- /**
664
- * Creates a new Session object.
665
- *
666
- * Note: This function is typically not invoked directly by application code.
667
- * Instead, use a `SessionStorage` object's `getSession` method.
668
- *
669
- * @see https://remix.run/utils/sessions#createsession
670
- */
671
- declare const createSession: CreateSessionFunction;
672
- type IsSessionFunction = (object: any) => object is Session;
673
- /**
674
- * Returns true if an object is a Remix session.
675
- *
676
- * @see https://remix.run/utils/sessions#issession
677
- */
678
- declare const isSession: IsSessionFunction;
679
- /**
680
- * SessionStorage stores session data between HTTP requests and knows how to
681
- * parse and create cookies.
682
- *
683
- * A SessionStorage creates Session objects using a `Cookie` header as input.
684
- * Then, later it generates the `Set-Cookie` header to be used in the response.
685
- */
686
- interface SessionStorage<Data = SessionData, FlashData = Data> {
687
- /**
688
- * Parses a Cookie header from a HTTP request and returns the associated
689
- * Session. If there is no session associated with the cookie, this will
690
- * return a new Session with no data.
691
- */
692
- getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
693
- /**
694
- * Stores all data in the Session and returns the Set-Cookie header to be
695
- * used in the HTTP response.
696
- */
697
- commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
698
- /**
699
- * Deletes all data associated with the Session and returns the Set-Cookie
700
- * header to be used in the HTTP response.
701
- */
702
- destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
703
- }
704
- /**
705
- * SessionIdStorageStrategy is designed to allow anyone to easily build their
706
- * own SessionStorage using `createSessionStorage(strategy)`.
707
- *
708
- * This strategy describes a common scenario where the session id is stored in
709
- * a cookie but the actual session data is stored elsewhere, usually in a
710
- * database or on disk. A set of create, read, update, and delete operations
711
- * are provided for managing the session data.
712
- */
713
- interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
714
- /**
715
- * The Cookie used to store the session id, or options used to automatically
716
- * create one.
717
- */
718
- cookie?: Cookie | (CookieOptions & {
719
- name?: string;
720
- });
721
- /**
722
- * Creates a new record with the given data and returns the session id.
723
- */
724
- createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
725
- /**
726
- * Returns data for a given session id, or `null` if there isn't any.
727
- */
728
- readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
729
- /**
730
- * Updates data for the given session id.
731
- */
732
- updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
733
- /**
734
- * Deletes data for a given session id from the data store.
735
- */
736
- deleteData: (id: string) => Promise<void>;
737
- }
738
- /**
739
- * Creates a SessionStorage object using a SessionIdStorageStrategy.
740
- *
741
- * Note: This is a low-level API that should only be used if none of the
742
- * existing session storage options meet your requirements.
743
- */
744
- declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
745
-
746
- interface CookieSessionStorageOptions {
747
- /**
748
- * The Cookie used to store the session data on the client, or options used
749
- * to automatically create one.
750
- */
751
- cookie?: SessionIdStorageStrategy["cookie"];
752
- }
753
- /**
754
- * Creates and returns a SessionStorage object that stores all session data
755
- * directly in the session cookie itself.
756
- *
757
- * This has the advantage that no database or other backend services are
758
- * needed, and can help to simplify some load-balanced scenarios. However, it
759
- * also has the limitation that serialized session data may not exceed the
760
- * browser's maximum cookie size. Trade-offs!
761
- */
762
- declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
763
-
764
- interface MemorySessionStorageOptions {
765
- /**
766
- * The Cookie used to store the session id on the client, or options used
767
- * to automatically create one.
768
- */
769
- cookie?: SessionIdStorageStrategy["cookie"];
770
- }
771
- /**
772
- * Creates and returns a simple in-memory SessionStorage object, mostly useful
773
- * for testing and as a reference implementation.
774
- *
775
- * Note: This storage does not scale beyond a single process, so it is not
776
- * suitable for most production scenarios.
777
- */
778
- declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
779
-
780
- type DevServerHooks = {
781
- getCriticalCss?: (pathname: string) => Promise<string | undefined>;
782
- processRequestError?: (error: unknown) => void;
783
- };
784
- declare function setDevServerHooks(devServerHooks: DevServerHooks): void;
785
-
786
- /**
787
- * Apps can use this interface to "register" app-wide types for React Router via interface declaration merging and module augmentation.
788
- * React Router should handle this for you via type generation.
789
- *
790
- * For more on declaration merging and module augmentation, see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation .
791
- */
792
- interface Register {
793
- }
794
-
795
- type AnyParams = Record<string, Record<string, string | undefined>>;
796
- type Params = Register extends {
797
- params: infer RegisteredParams extends AnyParams;
798
- } ? RegisteredParams : AnyParams;
799
- type Args = {
800
- [K in keyof Params]: ToArgs<Params[K]>;
801
- };
802
- type ToArgs<T> = Equal<T, {}> extends true ? [] : Partial<T> extends T ? [T] | [] : [
803
- T
804
- ];
805
- /**
806
- Returns a resolved URL path for the specified route.
807
-
808
- ```tsx
809
- const h = href("/:lang?/about", { lang: "en" })
810
- // -> `/en/about`
811
-
812
- <Link to={href("/products/:id", { id: "abc123" })} />
813
- ```
814
- */
815
- declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
816
-
817
- declare function routeRSCServerRequest(request: Request, requestServer: (request: Request) => Promise<Response>, decode: (body: ReadableStream<Uint8Array>) => Promise<ServerPayload>, renderHTML: (payload: ServerPayload) => ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>): Promise<Response>;
818
- declare function RSCStaticRouter({ payload }: {
819
- payload: ServerPayload;
820
- }): React.JSX.Element | null;
821
-
822
- declare function deserializeErrors(errors: RouterState["errors"]): RouterState["errors"];
823
-
824
- type RemixErrorBoundaryProps = React.PropsWithChildren<{
825
- location: Location;
826
- isOutsideRemixApp?: boolean;
827
- error?: Error;
828
- }>;
829
- type RemixErrorBoundaryState = {
830
- error: null | Error;
831
- location: Location;
832
- };
833
- declare class RemixErrorBoundary extends React.Component<RemixErrorBoundaryProps, RemixErrorBoundaryState> {
834
- constructor(props: RemixErrorBoundaryProps);
835
- static getDerivedStateFromError(error: Error): {
836
- error: Error;
837
- };
838
- static getDerivedStateFromProps(props: RemixErrorBoundaryProps, state: RemixErrorBoundaryState): {
839
- error: Error | null;
840
- location: Location<any>;
841
- };
842
- render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
843
- }
844
-
845
- declare function getHydrationData(state: {
846
- loaderData?: Router["state"]["loaderData"];
847
- actionData?: Router["state"]["actionData"];
848
- errors?: Router["state"]["errors"];
849
- }, routes: DataRouteObject[], getRouteInfo: (routeId: string) => {
850
- clientLoader: ClientLoaderFunction | undefined;
851
- hasLoader: boolean;
852
- hasHydrateFallback: boolean;
853
- }, location: Path, basename: string | undefined, isSpaMode: boolean): HydrationState;
854
-
855
- export { ActionFunction, ActionFunctionArgs, AppLoadContext, Blocker, BlockerFunction, ClientLoaderFunction, type Cookie, type CookieOptions, type CookieSignatureOptions, type CreateRequestHandlerFunction, DataRouteObject, Router as DataRouter, DataStrategyFunction, EntryContext, type FlashSessionData, type HandleDataRequestFunction, type HandleDocumentRequestFunction, type HandleErrorFunction, HydrationState, IndexRouteObject, InitialEntry, type IsCookieFunction, type IsSessionFunction, LinksFunction, LoaderFunction, LoaderFunctionArgs, Location, MetaFunction, type NavigateFunction, NavigateOptions, Navigation, Action as NavigationType, NonIndexRouteObject, ParamParseKey, Params$1 as Params, Path, PathMatch, PathPattern, RSCStaticRouter, type Register, RelativeRoutingType, type RequestHandler, RevalidationState, RouteObject, RouterState, type RoutesTestStubProps, type ServerBuild, type ServerEntryModule, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, StaticHandler, StaticHandlerContext, StaticRouter, type StaticRouterProps, StaticRouterProvider, type StaticRouterProviderProps, To, UIMatch, AssetsManifest as UNSAFE_AssetsManifest, MiddlewareEnabled as UNSAFE_MiddlewareEnabled, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteModules as UNSAFE_RouteModules, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getHydrationData as UNSAFE_getHydrationData, getTurboStreamSingleFetchDataStrategy as UNSAFE_getTurboStreamSingleFetchDataStrategy, createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createRoutesStub, createSession, createSessionStorage, createStaticHandler, createStaticRouter, href, isCookie, isSession, routeRSCServerRequest, unstable_InitialContext, unstable_RouterContextProvider, setDevServerHooks as unstable_setDevServerHooks, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };