You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-router/lib/router/utils.ts
+63Lines changed: 63 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -116,8 +116,28 @@ export type Submission =
116
116
* this as a private implementation detail in case they diverge in the future.
117
117
*/
118
118
interfaceDataFunctionArgs<Context>{
119
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
119
120
request: Request;
121
+
/**
122
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
123
+
* @example
124
+
* // app/routes.ts
125
+
* route("teams/:teamId", "./team.tsx"),
126
+
*
127
+
* // app/team.tsx
128
+
* export function loader({
129
+
* params,
130
+
* }: Route.LoaderArgs) {
131
+
* params.teamId;
132
+
* // ^ string
133
+
* }
134
+
**/
120
135
params: Params;
136
+
/**
137
+
* This is the context passed in to your server adapter's getLoadContext() function.
138
+
* It's a way to bridge the gap between the adapter's request/response API with your React Router app.
139
+
* It is only applicable if you are using a custom server adapter.
/** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
169
190
currentUrl: URL;
191
+
/** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
170
192
currentParams: AgnosticDataRouteMatch["params"];
193
+
/** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
171
194
nextUrl: URL;
195
+
/** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
172
196
nextParams: AgnosticDataRouteMatch["params"];
197
+
/** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
173
198
formMethod?: Submission["formMethod"];
199
+
/** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
174
200
formAction?: Submission["formAction"];
201
+
/** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
175
202
formEncType?: Submission["formEncType"];
203
+
/** The form submission data when the form's encType is `text/plain` */
176
204
text?: Submission["text"];
205
+
/** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
177
206
formData?: Submission["formData"];
207
+
/** The form submission data when the form's encType is `application/json` */
178
208
json?: Submission["json"];
209
+
/** The status code of the action response */
179
210
actionStatus?: number;
211
+
/**
212
+
* When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
213
+
*
214
+
* @example
215
+
* export async function action() {
216
+
* await saveSomeStuff();
217
+
* return { ok: true };
218
+
* }
219
+
*
220
+
* export function shouldRevalidate({
221
+
* actionResult,
222
+
* }) {
223
+
* if (actionResult?.ok) {
224
+
* return false;
225
+
* }
226
+
* return true;
227
+
* }
228
+
*/
180
229
actionResult?: any;
230
+
/**
231
+
* By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
232
+
*
233
+
* /projects/123/tasks/abc
234
+
* /projects/123/tasks/def
235
+
* React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
236
+
*
237
+
* It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
238
+
*/
181
239
defaultShouldRevalidate: boolean;
182
240
}
183
241
@@ -556,8 +614,13 @@ export function matchRoutesImpl<
Copy file name to clipboardExpand all lines: packages/react-router/lib/types/route-module.ts
+80-1Lines changed: 80 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -51,10 +51,15 @@ type MetaMatches<T extends RouteInfo[]> =
51
51
: Array<MetaMatch<RouteInfo>|undefined>;
52
52
53
53
exporttypeCreateMetaArgs<TextendsRouteInfo>={
54
+
/** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
54
55
location: Location;
56
+
/** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
55
57
params: T["params"];
58
+
/** The return value for this route's server loader function */
56
59
data: T["loaderData"];
60
+
/** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
57
61
error?: unknown;
62
+
/** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
58
63
matches: MetaMatches<[...T["parents"],T]>;
59
64
};
60
65
exporttypeMetaDescriptors=MetaDescriptor[];
@@ -109,11 +114,52 @@ type _CreateActionData<ServerActionData, ClientActionData> = Awaited<
109
114
>
110
115
111
116
typeClientDataFunctionArgs<TextendsRouteInfo>={
117
+
/**
118
+
* 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.
119
+
*
120
+
* @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.
121
+
**/
112
122
request: Request;
123
+
/**
124
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
/** 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. */
142
+
request: Request;
143
+
/**
144
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
145
+
* @example
146
+
* // app/routes.ts
147
+
* route("teams/:teamId", "./team.tsx"),
148
+
*
149
+
* // app/team.tsx
150
+
* export function loader({
151
+
* params,
152
+
* }: Route.LoaderArgs) {
153
+
* params.teamId;
154
+
* // ^ string
155
+
* }
156
+
**/
157
+
params: T["params"];
158
+
/**
159
+
* This is the context passed in to your server adapter's getLoadContext() function.
160
+
* It's a way to bridge the gap between the adapter's request/response API with your React Router app.
161
+
* It is only applicable if you are using a custom server adapter.
162
+
*/
117
163
context: AppLoadContext;
118
164
};
119
165
@@ -122,6 +168,7 @@ export type CreateServerLoaderArgs<T extends RouteInfo> =
/** 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). */
/** 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. */
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
207
+
* @example
208
+
* // app/routes.ts
209
+
* route("teams/:teamId", "./team.tsx"),
210
+
*
211
+
* // app/team.tsx
212
+
* export default function Component({
213
+
* params,
214
+
* }: Route.ComponentProps) {
215
+
* params.teamId;
216
+
* // ^ string
217
+
* }
218
+
**/
157
219
params: T["params"];
220
+
/** The data returned from the `loader` or `clientLoader` */
158
221
loaderData: T["loaderData"];
222
+
/** The data returned from the `action` or `clientAction` following an action submission. */
159
223
actionData?: T["actionData"];
224
+
/** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
0 commit comments