UNPKG

9.09 kBTypeScriptView Raw
1import { R as RouteModule, f as LinkDescriptor, L as Location, F as Func, g as Pretty, h as MetaDescriptor, G as GetLoaderData, i as ServerDataFunctionArgs, j as MiddlewareNextFunction, k as ClientDataFunctionArgs, D as DataStrategyResult, l as ServerDataFrom, N as Normalize, m as GetActionData } from '../../instrumentation--6Pioq_G.js';
2import { R as RouteFiles, P as Pages } from '../../register-CBoanF80.js';
3import 'react';
4
5type MaybePromise<T> = T | Promise<T>;
6type Props = {
7 params: unknown;
8 loaderData: unknown;
9 actionData: unknown;
10};
11type RouteInfo = Props & {
12 module: RouteModule;
13 matches: Array<MatchInfo>;
14};
15type MatchInfo = {
16 id: string;
17 module: RouteModule;
18};
19type MetaMatch<T extends MatchInfo> = Pretty<{
20 id: T["id"];
21 params: Record<string, string | undefined>;
22 pathname: string;
23 meta: MetaDescriptor[];
24 /** @deprecated Use `MetaMatch.loaderData` instead */
25 data: GetLoaderData<T["module"]>;
26 loaderData: GetLoaderData<T["module"]>;
27 handle?: unknown;
28 error?: unknown;
29}>;
30type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
31type HasErrorBoundary<T extends RouteInfo> = T["module"] extends {
32 ErrorBoundary: Func;
33} ? true : false;
34type CreateMetaArgs<T extends RouteInfo> = {
35 /** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
36 location: Location;
37 /** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
38 params: T["params"];
39 /**
40 * The return value for this route's server loader function
41 *
42 * @deprecated Use `Route.MetaArgs.loaderData` instead
43 */
44 data: T["loaderData"] | (HasErrorBoundary<T> extends true ? undefined : never);
45 /** The return value for this route's server loader function */
46 loaderData: T["loaderData"] | (HasErrorBoundary<T> extends true ? undefined : never);
47 /** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
48 error?: unknown;
49 /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
50 matches: MetaMatches<T["matches"]>;
51};
52type MetaDescriptors = MetaDescriptor[];
53type HeadersArgs = {
54 loaderHeaders: Headers;
55 parentHeaders: Headers;
56 actionHeaders: Headers;
57 errorHeaders: Headers | undefined;
58};
59type CreateServerMiddlewareFunction<T extends RouteInfo> = (args: ServerDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Response>) => MaybePromise<Response | void>;
60type CreateClientMiddlewareFunction<T extends RouteInfo> = (args: ClientDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Record<string, DataStrategyResult>>) => MaybePromise<Record<string, DataStrategyResult> | void>;
61type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
62type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
63 /** 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). */
64 serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
65};
66type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
67type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
68 /** 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. */
69 serverAction: () => Promise<ServerDataFrom<T["module"]["action"]>>;
70};
71type IsServerFirstRoute<T extends RouteInfo, RSCEnabled extends boolean> = RSCEnabled extends true ? T["module"] extends {
72 ServerComponent: Func;
73} ? true : false : false;
74type CreateHydrateFallbackProps<T extends RouteInfo, RSCEnabled extends boolean> = {
75 params: T["params"];
76} & (IsServerFirstRoute<T, RSCEnabled> extends true ? {
77 /** The data returned from the `loader` */
78 loaderData?: ServerDataFrom<T["module"]["loader"]>;
79 /** The data returned from the `action` following an action submission. */
80 actionData?: ServerDataFrom<T["module"]["action"]>;
81} : {
82 /** The data returned from the `loader` or `clientLoader` */
83 loaderData?: T["loaderData"];
84 /** The data returned from the `action` or `clientAction` following an action submission. */
85 actionData?: T["actionData"];
86});
87type Match<T extends MatchInfo> = Pretty<{
88 id: T["id"];
89 params: Record<string, string | undefined>;
90 pathname: string;
91 /** @deprecated Use `Match.loaderData` instead */
92 data: GetLoaderData<T["module"]>;
93 loaderData: GetLoaderData<T["module"]>;
94 handle: unknown;
95}>;
96type Matches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<MatchInfo> | undefined>;
97type CreateComponentProps<T extends RouteInfo, RSCEnabled extends boolean> = {
98 /**
99 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
100 * @example
101 * // app/routes.ts
102 * route("teams/:teamId", "./team.tsx"),
103 *
104 * // app/team.tsx
105 * export default function Component({
106 * params,
107 * }: Route.ComponentProps) {
108 * params.teamId;
109 * // ^ string
110 * }
111 **/
112 params: T["params"];
113 /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
114 matches: Matches<T["matches"]>;
115} & (IsServerFirstRoute<T, RSCEnabled> extends true ? {
116 /** The data returned from the `loader` */
117 loaderData: ServerDataFrom<T["module"]["loader"]>;
118 /** The data returned from the `action` following an action submission. */
119 actionData?: ServerDataFrom<T["module"]["action"]>;
120} : {
121 /** The data returned from the `loader` or `clientLoader` */
122 loaderData: T["loaderData"];
123 /** The data returned from the `action` or `clientAction` following an action submission. */
124 actionData?: T["actionData"];
125});
126type CreateErrorBoundaryProps<T extends RouteInfo, RSCEnabled extends boolean> = {
127 /**
128 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
129 * @example
130 * // app/routes.ts
131 * route("teams/:teamId", "./team.tsx"),
132 *
133 * // app/team.tsx
134 * export function ErrorBoundary({
135 * params,
136 * }: Route.ErrorBoundaryProps) {
137 * params.teamId;
138 * // ^ string
139 * }
140 **/
141 params: T["params"];
142 error: unknown;
143} & (IsServerFirstRoute<T, RSCEnabled> extends true ? {
144 /** The data returned from the `loader` */
145 loaderData?: ServerDataFrom<T["module"]["loader"]>;
146 /** The data returned from the `action` following an action submission. */
147 actionData?: ServerDataFrom<T["module"]["action"]>;
148} : {
149 /** The data returned from the `loader` or `clientLoader` */
150 loaderData?: T["loaderData"];
151 /** The data returned from the `action` or `clientAction` following an action submission. */
152 actionData?: T["actionData"];
153});
154type GetAnnotations<Info extends RouteInfo, RSCEnabled extends boolean> = {
155 LinkDescriptors: LinkDescriptor[];
156 LinksFunction: () => LinkDescriptor[];
157 MetaArgs: CreateMetaArgs<Info>;
158 MetaDescriptors: MetaDescriptors;
159 MetaFunction: (args: CreateMetaArgs<Info>) => MetaDescriptors;
160 HeadersArgs: HeadersArgs;
161 HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
162 MiddlewareFunction: CreateServerMiddlewareFunction<Info>;
163 ClientMiddlewareFunction: CreateClientMiddlewareFunction<Info>;
164 LoaderArgs: CreateServerLoaderArgs<Info>;
165 ClientLoaderArgs: CreateClientLoaderArgs<Info>;
166 ActionArgs: CreateServerActionArgs<Info>;
167 ClientActionArgs: CreateClientActionArgs<Info>;
168 HydrateFallbackProps: CreateHydrateFallbackProps<Info, RSCEnabled>;
169 ComponentProps: CreateComponentProps<Info, RSCEnabled>;
170 ErrorBoundaryProps: CreateErrorBoundaryProps<Info, RSCEnabled>;
171};
172
173type Params<RouteFile extends keyof RouteFiles> = Normalize<Pages[RouteFiles[RouteFile]["page"]]["params"]>;
174
175type GetInfo<T extends {
176 file: keyof RouteFiles;
177 module: RouteModule;
178}> = {
179 params: Params<T["file"]>;
180 loaderData: GetLoaderData<T["module"]>;
181 actionData: GetActionData<T["module"]>;
182};
183
184export type { GetAnnotations, GetInfo };