react-router 7.6.0 → 7.6.1-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/dist/development/dom-export.d.mts +1 -2
- package/dist/development/dom-export.js +1 -1
- package/dist/development/dom-export.mjs +23 -23
- package/dist/development/index.d.mts +3740 -260
- package/dist/development/index.d.ts +1762 -12
- package/dist/development/index.js +16 -7
- package/dist/development/index.mjs +11439 -121
- package/dist/development/internal-export.d.mts +504 -0
- package/dist/development/internal-export.d.ts +504 -0
- package/dist/development/{lib/types/route-module.js → internal-export.js} +4 -4
- package/dist/development/{lib/types/route-module.mjs → internal-export.mjs} +1 -1
- package/dist/production/dom-export.d.mts +1 -2
- package/dist/production/dom-export.js +1 -1
- package/dist/production/dom-export.mjs +23 -23
- package/dist/production/index.d.mts +3740 -260
- package/dist/production/index.d.ts +1762 -12
- package/dist/production/index.js +16 -7
- package/dist/production/index.mjs +11439 -121
- package/dist/production/internal-export.d.mts +504 -0
- package/dist/production/internal-export.d.ts +504 -0
- package/dist/production/{lib/types/route-module.js → internal-export.js} +4 -4
- package/dist/production/{lib/types/route-module.mjs → internal-export.mjs} +1 -1
- package/package.json +7 -7
- package/dist/development/chunk-D4RADZKF.mjs +0 -11556
- package/dist/development/lib/types/route-module.d.mts +0 -208
- package/dist/development/lib/types/route-module.d.ts +0 -208
- package/dist/development/lib-CCSAGgcP.d.mts +0 -1736
- package/dist/development/route-data-B9_30zbP.d.ts +0 -1749
- package/dist/development/route-data-C6QaL0wu.d.mts +0 -1749
- package/dist/production/chunk-CVXGOGHQ.mjs +0 -11556
- package/dist/production/lib/types/route-module.d.mts +0 -208
- package/dist/production/lib/types/route-module.d.ts +0 -208
- package/dist/production/lib-CCSAGgcP.d.mts +0 -1736
- package/dist/production/route-data-B9_30zbP.d.ts +0 -1749
- package/dist/production/route-data-C6QaL0wu.d.mts +0 -1749
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { RouteFiles, Pages } from 'react-router';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The pathname, search, and hash values of a URL.
|
|
5
|
+
*/
|
|
6
|
+
interface Path {
|
|
7
|
+
/**
|
|
8
|
+
* A URL pathname, beginning with a /.
|
|
9
|
+
*/
|
|
10
|
+
pathname: string;
|
|
11
|
+
/**
|
|
12
|
+
* A URL search string, beginning with a ?.
|
|
13
|
+
*/
|
|
14
|
+
search: string;
|
|
15
|
+
/**
|
|
16
|
+
* A URL fragment identifier, beginning with a #.
|
|
17
|
+
*/
|
|
18
|
+
hash: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An entry in a history stack. A location contains information about the
|
|
22
|
+
* URL path, as well as possibly some arbitrary state and a key.
|
|
23
|
+
*/
|
|
24
|
+
interface Location<State = any> extends Path {
|
|
25
|
+
/**
|
|
26
|
+
* A value of arbitrary data associated with this location.
|
|
27
|
+
*/
|
|
28
|
+
state: State;
|
|
29
|
+
/**
|
|
30
|
+
* A unique string associated with this location. May be used to safely store
|
|
31
|
+
* and retrieve data in some other storage API, like `localStorage`.
|
|
32
|
+
*
|
|
33
|
+
* Note: This value is always "default" on the initial location.
|
|
34
|
+
*/
|
|
35
|
+
key: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An augmentable interface users can modify in their app-code to opt into
|
|
40
|
+
* future-flag-specific types
|
|
41
|
+
*/
|
|
42
|
+
interface Future {
|
|
43
|
+
}
|
|
44
|
+
type MiddlewareEnabled = Future extends {
|
|
45
|
+
unstable_middleware: infer T extends boolean;
|
|
46
|
+
} ? T : false;
|
|
47
|
+
|
|
48
|
+
type MaybePromise$1<T> = T | Promise<T>;
|
|
49
|
+
interface unstable_RouterContext<T = unknown> {
|
|
50
|
+
defaultValue?: T;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A Map of RouterContext objects to their initial values - used to populate a
|
|
54
|
+
* fresh `context` value per request/navigation/fetch
|
|
55
|
+
*/
|
|
56
|
+
type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* Provides methods for writing/reading values in application context in a typesafe way.
|
|
59
|
+
*/
|
|
60
|
+
declare class unstable_RouterContextProvider {
|
|
61
|
+
#private;
|
|
62
|
+
constructor(init?: unstable_InitialContext);
|
|
63
|
+
get<T>(context: unstable_RouterContext<T>): T;
|
|
64
|
+
set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Route middleware `next` function to call downstream handlers and then complete
|
|
68
|
+
* middlewares from the bottom-up
|
|
69
|
+
*/
|
|
70
|
+
interface unstable_MiddlewareNextFunction<Result = unknown> {
|
|
71
|
+
(): MaybePromise$1<Result>;
|
|
72
|
+
}
|
|
73
|
+
declare class DataWithResponseInit<D> {
|
|
74
|
+
type: string;
|
|
75
|
+
data: D;
|
|
76
|
+
init: ResponseInit | null;
|
|
77
|
+
constructor(data: D, init?: ResponseInit);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* An object of unknown type for route loaders and actions provided by the
|
|
82
|
+
* server's `getLoadContext()` function. This is defined as an empty interface
|
|
83
|
+
* specifically so apps can leverage declaration merging to augment this type
|
|
84
|
+
* globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
|
|
85
|
+
*/
|
|
86
|
+
interface AppLoadContext {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
91
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
92
|
+
interface HtmlLinkProps {
|
|
93
|
+
/**
|
|
94
|
+
* Address of the hyperlink
|
|
95
|
+
*/
|
|
96
|
+
href?: string;
|
|
97
|
+
/**
|
|
98
|
+
* How the element handles crossorigin requests
|
|
99
|
+
*/
|
|
100
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
101
|
+
/**
|
|
102
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
103
|
+
*/
|
|
104
|
+
rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
|
|
105
|
+
/**
|
|
106
|
+
* Applicable media: "screen", "print", "(max-width: 764px)"
|
|
107
|
+
*/
|
|
108
|
+
media?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Integrity metadata used in Subresource Integrity checks
|
|
111
|
+
*/
|
|
112
|
+
integrity?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Language of the linked resource
|
|
115
|
+
*/
|
|
116
|
+
hrefLang?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Hint for the type of the referenced resource
|
|
119
|
+
*/
|
|
120
|
+
type?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Referrer policy for fetches initiated by the element
|
|
123
|
+
*/
|
|
124
|
+
referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
|
|
125
|
+
/**
|
|
126
|
+
* Sizes of the icons (for rel="icon")
|
|
127
|
+
*/
|
|
128
|
+
sizes?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
131
|
+
*/
|
|
132
|
+
as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
|
|
133
|
+
/**
|
|
134
|
+
* Color to use when customizing a site's icon (for rel="mask-icon")
|
|
135
|
+
*/
|
|
136
|
+
color?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Whether the link is disabled
|
|
139
|
+
*/
|
|
140
|
+
disabled?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
|
|
143
|
+
*/
|
|
144
|
+
title?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
147
|
+
* small monitors, etc. (for rel="preload")
|
|
148
|
+
*/
|
|
149
|
+
imageSrcSet?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
152
|
+
*/
|
|
153
|
+
imageSizes?: string;
|
|
154
|
+
}
|
|
155
|
+
interface HtmlLinkPreloadImage extends HtmlLinkProps {
|
|
156
|
+
/**
|
|
157
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
158
|
+
*/
|
|
159
|
+
rel: "preload";
|
|
160
|
+
/**
|
|
161
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
162
|
+
*/
|
|
163
|
+
as: "image";
|
|
164
|
+
/**
|
|
165
|
+
* Address of the hyperlink
|
|
166
|
+
*/
|
|
167
|
+
href?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
170
|
+
* small monitors, etc. (for rel="preload")
|
|
171
|
+
*/
|
|
172
|
+
imageSrcSet: string;
|
|
173
|
+
/**
|
|
174
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
175
|
+
*/
|
|
176
|
+
imageSizes?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Represents a `<link>` element.
|
|
180
|
+
*
|
|
181
|
+
* WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
|
|
182
|
+
*/
|
|
183
|
+
type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
|
|
184
|
+
imageSizes?: never;
|
|
185
|
+
});
|
|
186
|
+
interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
|
|
187
|
+
/**
|
|
188
|
+
* The absolute path of the page to prefetch.
|
|
189
|
+
*/
|
|
190
|
+
page: string;
|
|
191
|
+
}
|
|
192
|
+
type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
|
|
193
|
+
|
|
194
|
+
type MetaDescriptor = {
|
|
195
|
+
charSet: "utf-8";
|
|
196
|
+
} | {
|
|
197
|
+
title: string;
|
|
198
|
+
} | {
|
|
199
|
+
name: string;
|
|
200
|
+
content: string;
|
|
201
|
+
} | {
|
|
202
|
+
property: string;
|
|
203
|
+
content: string;
|
|
204
|
+
} | {
|
|
205
|
+
httpEquiv: string;
|
|
206
|
+
content: string;
|
|
207
|
+
} | {
|
|
208
|
+
"script:ld+json": LdJsonObject;
|
|
209
|
+
} | {
|
|
210
|
+
tagName: "meta" | "link";
|
|
211
|
+
[name: string]: string;
|
|
212
|
+
} | {
|
|
213
|
+
[name: string]: unknown;
|
|
214
|
+
};
|
|
215
|
+
type LdJsonObject = {
|
|
216
|
+
[Key in string]: LdJsonValue;
|
|
217
|
+
} & {
|
|
218
|
+
[Key in string]?: LdJsonValue | undefined;
|
|
219
|
+
};
|
|
220
|
+
type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
|
|
221
|
+
type LdJsonPrimitive = string | number | boolean | null;
|
|
222
|
+
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
223
|
+
|
|
224
|
+
type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
|
|
225
|
+
[key: PropertyKey]: Serializable;
|
|
226
|
+
} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A brand that can be applied to a type to indicate that it will serialize
|
|
230
|
+
* to a specific type when transported to the client from a loader.
|
|
231
|
+
* Only use this if you have additional serialization/deserialization logic
|
|
232
|
+
* in your application.
|
|
233
|
+
*/
|
|
234
|
+
type unstable_SerializesTo<T> = {
|
|
235
|
+
unstable__ReactRouter_SerializesTo: [T];
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
239
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
240
|
+
type Func = (...args: any[]) => unknown;
|
|
241
|
+
type Pretty<T> = {
|
|
242
|
+
[K in keyof T]: T[K];
|
|
243
|
+
} & {};
|
|
244
|
+
type Normalize<T> = _Normalize<UnionKeys<T>, T>;
|
|
245
|
+
type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
|
|
246
|
+
[K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
|
|
247
|
+
} & {
|
|
248
|
+
[K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
|
|
249
|
+
} & {
|
|
250
|
+
[K in Key as K extends keyof U ? never : K]?: undefined;
|
|
251
|
+
}> : never;
|
|
252
|
+
type UnionKeys<T> = T extends any ? keyof T : never;
|
|
253
|
+
|
|
254
|
+
type RouteModule = {
|
|
255
|
+
meta?: Func;
|
|
256
|
+
links?: Func;
|
|
257
|
+
headers?: Func;
|
|
258
|
+
loader?: Func;
|
|
259
|
+
clientLoader?: Func;
|
|
260
|
+
action?: Func;
|
|
261
|
+
clientAction?: Func;
|
|
262
|
+
HydrateFallback?: Func;
|
|
263
|
+
default?: Func;
|
|
264
|
+
ErrorBoundary?: Func;
|
|
265
|
+
[key: string]: unknown;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
|
|
269
|
+
[K in keyof T]: Serialize<T[K]>;
|
|
270
|
+
} : undefined;
|
|
271
|
+
type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
|
|
272
|
+
type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
|
|
273
|
+
type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
|
|
274
|
+
type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
|
|
275
|
+
type ServerDataFrom<T> = ServerData<DataFrom<T>>;
|
|
276
|
+
type ClientDataFrom<T> = ClientData<DataFrom<T>>;
|
|
277
|
+
type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
|
|
278
|
+
type IsHydrate<ClientLoader> = ClientLoader extends {
|
|
279
|
+
hydrate: true;
|
|
280
|
+
} ? true : ClientLoader extends {
|
|
281
|
+
hydrate: false;
|
|
282
|
+
} ? false : false;
|
|
283
|
+
type GetLoaderData<T extends RouteModule> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
|
|
284
|
+
HydrateFallback: Func;
|
|
285
|
+
} ? true : false>;
|
|
286
|
+
type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
|
|
287
|
+
HasHydrateFallback,
|
|
288
|
+
ClientLoaderHydrate
|
|
289
|
+
] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
|
|
290
|
+
IsDefined<ClientLoaderData>,
|
|
291
|
+
IsDefined<ServerLoaderData>
|
|
292
|
+
] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
|
|
293
|
+
type GetActionData<T extends RouteModule> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
|
|
294
|
+
type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
|
|
295
|
+
IsDefined<ServerActionData>,
|
|
296
|
+
IsDefined<ClientActionData>
|
|
297
|
+
] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
|
|
298
|
+
|
|
299
|
+
type Params<RouteFile extends keyof RouteFiles> = Normalize<Pages[RouteFiles[RouteFile]["page"]]["params"]>;
|
|
300
|
+
|
|
301
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
302
|
+
type Props = {
|
|
303
|
+
params: unknown;
|
|
304
|
+
loaderData: unknown;
|
|
305
|
+
actionData: unknown;
|
|
306
|
+
};
|
|
307
|
+
type RouteInfo = Props & {
|
|
308
|
+
module: RouteModule;
|
|
309
|
+
matches: Array<MatchInfo>;
|
|
310
|
+
};
|
|
311
|
+
type MatchInfo = {
|
|
312
|
+
id: string;
|
|
313
|
+
module: RouteModule;
|
|
314
|
+
};
|
|
315
|
+
type MetaMatch<T extends MatchInfo> = Pretty<{
|
|
316
|
+
id: T["id"];
|
|
317
|
+
params: Record<string, string | undefined>;
|
|
318
|
+
pathname: string;
|
|
319
|
+
meta: MetaDescriptor[];
|
|
320
|
+
data: GetLoaderData<T["module"]>;
|
|
321
|
+
handle?: unknown;
|
|
322
|
+
error?: unknown;
|
|
323
|
+
}>;
|
|
324
|
+
type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
|
|
325
|
+
type CreateMetaArgs<T extends RouteInfo> = {
|
|
326
|
+
/** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
|
|
327
|
+
location: Location;
|
|
328
|
+
/** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
|
|
329
|
+
params: T["params"];
|
|
330
|
+
/** The return value for this route's server loader function */
|
|
331
|
+
data: T["loaderData"] | undefined;
|
|
332
|
+
/** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
|
|
333
|
+
error?: unknown;
|
|
334
|
+
/** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
|
|
335
|
+
matches: MetaMatches<T["matches"]>;
|
|
336
|
+
};
|
|
337
|
+
type MetaDescriptors = MetaDescriptor[];
|
|
338
|
+
type HeadersArgs = {
|
|
339
|
+
loaderHeaders: Headers;
|
|
340
|
+
parentHeaders: Headers;
|
|
341
|
+
actionHeaders: Headers;
|
|
342
|
+
errorHeaders: Headers | undefined;
|
|
343
|
+
};
|
|
344
|
+
type ClientDataFunctionArgs<T extends RouteInfo> = {
|
|
345
|
+
/**
|
|
346
|
+
* A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
|
|
347
|
+
*
|
|
348
|
+
* @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
|
|
349
|
+
**/
|
|
350
|
+
request: Request;
|
|
351
|
+
/**
|
|
352
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
353
|
+
* @example
|
|
354
|
+
* // app/routes.ts
|
|
355
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
356
|
+
*
|
|
357
|
+
* // app/team.tsx
|
|
358
|
+
* export function clientLoader({
|
|
359
|
+
* params,
|
|
360
|
+
* }: Route.ClientLoaderArgs) {
|
|
361
|
+
* params.teamId;
|
|
362
|
+
* // ^ string
|
|
363
|
+
* }
|
|
364
|
+
**/
|
|
365
|
+
params: T["params"];
|
|
366
|
+
/**
|
|
367
|
+
* When `future.unstable_middleware` is not enabled, this is undefined.
|
|
368
|
+
*
|
|
369
|
+
* When `future.unstable_middleware` is enabled, this is an instance of
|
|
370
|
+
* `unstable_RouterContextProvider` and can be used to access context values
|
|
371
|
+
* from your route middlewares. You may pass in initial context values in your
|
|
372
|
+
* `<HydratedRouter unstable_getContext>` prop
|
|
373
|
+
*/
|
|
374
|
+
context: unstable_RouterContextProvider;
|
|
375
|
+
};
|
|
376
|
+
type ServerDataFunctionArgs<T extends RouteInfo> = {
|
|
377
|
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */
|
|
378
|
+
request: Request;
|
|
379
|
+
/**
|
|
380
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
381
|
+
* @example
|
|
382
|
+
* // app/routes.ts
|
|
383
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
384
|
+
*
|
|
385
|
+
* // app/team.tsx
|
|
386
|
+
* export function loader({
|
|
387
|
+
* params,
|
|
388
|
+
* }: Route.LoaderArgs) {
|
|
389
|
+
* params.teamId;
|
|
390
|
+
* // ^ string
|
|
391
|
+
* }
|
|
392
|
+
**/
|
|
393
|
+
params: T["params"];
|
|
394
|
+
/**
|
|
395
|
+
* Without `future.unstable_middleware` enabled, this is the context passed in
|
|
396
|
+
* to your server adapter's `getLoadContext` function. It's a way to bridge the
|
|
397
|
+
* gap between the adapter's request/response API with your React Router app.
|
|
398
|
+
* It is only applicable if you are using a custom server adapter.
|
|
399
|
+
*
|
|
400
|
+
* With `future.unstable_middleware` enabled, this is an instance of
|
|
401
|
+
* `unstable_RouterContextProvider` and can be used for type-safe access to
|
|
402
|
+
* context value set in your route middlewares. If you are using a custom
|
|
403
|
+
* server adapter, you may provide an initial set of context values from your
|
|
404
|
+
* `getLoadContext` function.
|
|
405
|
+
*/
|
|
406
|
+
context: MiddlewareEnabled extends true ? unstable_RouterContextProvider : AppLoadContext;
|
|
407
|
+
};
|
|
408
|
+
type CreateServerMiddlewareFunction<T extends RouteInfo> = (args: ServerDataFunctionArgs<T>, next: unstable_MiddlewareNextFunction<Response>) => MaybePromise<Response | void>;
|
|
409
|
+
type CreateClientMiddlewareFunction<T extends RouteInfo> = (args: ClientDataFunctionArgs<T>, next: unstable_MiddlewareNextFunction<undefined>) => MaybePromise<void>;
|
|
410
|
+
type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
|
|
411
|
+
type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
|
|
412
|
+
/** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */
|
|
413
|
+
serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
|
|
414
|
+
};
|
|
415
|
+
type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>;
|
|
416
|
+
type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
|
|
417
|
+
/** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */
|
|
418
|
+
serverAction: () => Promise<ServerDataFrom<T["module"]["action"]>>;
|
|
419
|
+
};
|
|
420
|
+
type CreateHydrateFallbackProps<T extends RouteInfo> = {
|
|
421
|
+
params: T["params"];
|
|
422
|
+
loaderData?: T["loaderData"];
|
|
423
|
+
actionData?: T["actionData"];
|
|
424
|
+
};
|
|
425
|
+
type Match<T extends MatchInfo> = Pretty<{
|
|
426
|
+
id: T["id"];
|
|
427
|
+
params: Record<string, string | undefined>;
|
|
428
|
+
pathname: string;
|
|
429
|
+
data: GetLoaderData<T["module"]>;
|
|
430
|
+
handle: unknown;
|
|
431
|
+
}>;
|
|
432
|
+
type Matches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<MatchInfo> | undefined>;
|
|
433
|
+
type CreateComponentProps<T extends RouteInfo> = {
|
|
434
|
+
/**
|
|
435
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
436
|
+
* @example
|
|
437
|
+
* // app/routes.ts
|
|
438
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
439
|
+
*
|
|
440
|
+
* // app/team.tsx
|
|
441
|
+
* export default function Component({
|
|
442
|
+
* params,
|
|
443
|
+
* }: Route.ComponentProps) {
|
|
444
|
+
* params.teamId;
|
|
445
|
+
* // ^ string
|
|
446
|
+
* }
|
|
447
|
+
**/
|
|
448
|
+
params: T["params"];
|
|
449
|
+
/** The data returned from the `loader` or `clientLoader` */
|
|
450
|
+
loaderData: T["loaderData"];
|
|
451
|
+
/** The data returned from the `action` or `clientAction` following an action submission. */
|
|
452
|
+
actionData?: T["actionData"];
|
|
453
|
+
/** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
|
|
454
|
+
matches: Matches<T["matches"]>;
|
|
455
|
+
};
|
|
456
|
+
type CreateErrorBoundaryProps<T extends RouteInfo> = {
|
|
457
|
+
/**
|
|
458
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
459
|
+
* @example
|
|
460
|
+
* // app/routes.ts
|
|
461
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
462
|
+
*
|
|
463
|
+
* // app/team.tsx
|
|
464
|
+
* export function ErrorBoundary({
|
|
465
|
+
* params,
|
|
466
|
+
* }: Route.ErrorBoundaryProps) {
|
|
467
|
+
* params.teamId;
|
|
468
|
+
* // ^ string
|
|
469
|
+
* }
|
|
470
|
+
**/
|
|
471
|
+
params: T["params"];
|
|
472
|
+
error: unknown;
|
|
473
|
+
loaderData?: T["loaderData"];
|
|
474
|
+
actionData?: T["actionData"];
|
|
475
|
+
};
|
|
476
|
+
type GetAnnotations<Info extends RouteInfo> = {
|
|
477
|
+
LinkDescriptors: LinkDescriptor[];
|
|
478
|
+
LinksFunction: () => LinkDescriptor[];
|
|
479
|
+
MetaArgs: CreateMetaArgs<Info>;
|
|
480
|
+
MetaDescriptors: MetaDescriptors;
|
|
481
|
+
MetaFunction: (args: CreateMetaArgs<Info>) => MetaDescriptors;
|
|
482
|
+
HeadersArgs: HeadersArgs;
|
|
483
|
+
HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
|
|
484
|
+
unstable_MiddlewareFunction: CreateServerMiddlewareFunction<Info>;
|
|
485
|
+
unstable_ClientMiddlewareFunction: CreateClientMiddlewareFunction<Info>;
|
|
486
|
+
LoaderArgs: CreateServerLoaderArgs<Info>;
|
|
487
|
+
ClientLoaderArgs: CreateClientLoaderArgs<Info>;
|
|
488
|
+
ActionArgs: CreateServerActionArgs<Info>;
|
|
489
|
+
ClientActionArgs: CreateClientActionArgs<Info>;
|
|
490
|
+
HydrateFallbackProps: CreateHydrateFallbackProps<Info>;
|
|
491
|
+
ComponentProps: CreateComponentProps<Info>;
|
|
492
|
+
ErrorBoundaryProps: CreateErrorBoundaryProps<Info>;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
type GetInfo<T extends {
|
|
496
|
+
file: keyof RouteFiles;
|
|
497
|
+
module: RouteModule;
|
|
498
|
+
}> = {
|
|
499
|
+
params: Params<T["file"]>;
|
|
500
|
+
loaderData: GetLoaderData<T["module"]>;
|
|
501
|
+
actionData: GetActionData<T["module"]>;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
export type { GetAnnotations, GetInfo };
|