instrumentation-BB0wRuqz.d.ts 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273
  1. import * as React from 'react';
  2. import { ComponentType, ReactElement } from 'react';
  3. /**
  4. * An augmentable interface users can modify in their app-code to opt into
  5. * future-flag-specific types
  6. */
  7. interface Future {
  8. }
  9. type MiddlewareEnabled = Future extends {
  10. v8_middleware: infer T extends boolean;
  11. } ? T : false;
  12. /**
  13. * Actions represent the type of change to a location value.
  14. */
  15. declare enum Action {
  16. /**
  17. * A POP indicates a change to an arbitrary index in the history stack, such
  18. * as a back or forward navigation. It does not describe the direction of the
  19. * navigation, only that the current index changed.
  20. *
  21. * Note: This is the default action for newly created history objects.
  22. */
  23. Pop = "POP",
  24. /**
  25. * A PUSH indicates a new entry being added to the history stack, such as when
  26. * a link is clicked and a new page loads. When this happens, all subsequent
  27. * entries in the stack are lost.
  28. */
  29. Push = "PUSH",
  30. /**
  31. * A REPLACE indicates the entry at the current index in the history stack
  32. * being replaced by a new one.
  33. */
  34. Replace = "REPLACE"
  35. }
  36. /**
  37. * The pathname, search, and hash values of a URL.
  38. */
  39. interface Path {
  40. /**
  41. * A URL pathname, beginning with a /.
  42. */
  43. pathname: string;
  44. /**
  45. * A URL search string, beginning with a ?.
  46. */
  47. search: string;
  48. /**
  49. * A URL fragment identifier, beginning with a #.
  50. */
  51. hash: string;
  52. }
  53. /**
  54. * An entry in a history stack. A location contains information about the
  55. * URL path, as well as possibly some arbitrary state and a key.
  56. */
  57. interface Location<State = any> extends Path {
  58. /**
  59. * A value of arbitrary data associated with this location.
  60. */
  61. state: State;
  62. /**
  63. * A unique string associated with this location. May be used to safely store
  64. * and retrieve data in some other storage API, like `localStorage`.
  65. *
  66. * Note: This value is always "default" on the initial location.
  67. */
  68. key: string;
  69. }
  70. /**
  71. * A change to the current location.
  72. */
  73. interface Update {
  74. /**
  75. * The action that triggered the change.
  76. */
  77. action: Action;
  78. /**
  79. * The new location.
  80. */
  81. location: Location;
  82. /**
  83. * The delta between this location and the former location in the history stack
  84. */
  85. delta: number | null;
  86. }
  87. /**
  88. * A function that receives notifications about location changes.
  89. */
  90. interface Listener {
  91. (update: Update): void;
  92. }
  93. /**
  94. * Describes a location that is the destination of some navigation used in
  95. * {@link Link}, {@link useNavigate}, etc.
  96. */
  97. type To = string | Partial<Path>;
  98. /**
  99. * A history is an interface to the navigation stack. The history serves as the
  100. * source of truth for the current location, as well as provides a set of
  101. * methods that may be used to change it.
  102. *
  103. * It is similar to the DOM's `window.history` object, but with a smaller, more
  104. * focused API.
  105. */
  106. interface History {
  107. /**
  108. * The last action that modified the current location. This will always be
  109. * Action.Pop when a history instance is first created. This value is mutable.
  110. */
  111. readonly action: Action;
  112. /**
  113. * The current location. This value is mutable.
  114. */
  115. readonly location: Location;
  116. /**
  117. * Returns a valid href for the given `to` value that may be used as
  118. * the value of an <a href> attribute.
  119. *
  120. * @param to - The destination URL
  121. */
  122. createHref(to: To): string;
  123. /**
  124. * Returns a URL for the given `to` value
  125. *
  126. * @param to - The destination URL
  127. */
  128. createURL(to: To): URL;
  129. /**
  130. * Encode a location the same way window.history would do (no-op for memory
  131. * history) so we ensure our PUSH/REPLACE navigations for data routers
  132. * behave the same as POP
  133. *
  134. * @param to Unencoded path
  135. */
  136. encodeLocation(to: To): Path;
  137. /**
  138. * Pushes a new location onto the history stack, increasing its length by one.
  139. * If there were any entries in the stack after the current one, they are
  140. * lost.
  141. *
  142. * @param to - The new URL
  143. * @param state - Data to associate with the new location
  144. */
  145. push(to: To, state?: any): void;
  146. /**
  147. * Replaces the current location in the history stack with a new one. The
  148. * location that was replaced will no longer be available.
  149. *
  150. * @param to - The new URL
  151. * @param state - Data to associate with the new location
  152. */
  153. replace(to: To, state?: any): void;
  154. /**
  155. * Navigates `n` entries backward/forward in the history stack relative to the
  156. * current index. For example, a "back" navigation would use go(-1).
  157. *
  158. * @param delta - The delta in the stack index
  159. */
  160. go(delta: number): void;
  161. /**
  162. * Sets up a listener that will be called whenever the current location
  163. * changes.
  164. *
  165. * @param listener - A function that will be called when the location changes
  166. * @returns unlisten - A function that may be used to stop listening
  167. */
  168. listen(listener: Listener): () => void;
  169. }
  170. /**
  171. * A user-supplied object that describes a location. Used when providing
  172. * entries to `createMemoryHistory` via its `initialEntries` option.
  173. */
  174. type InitialEntry = string | Partial<Location>;
  175. /**
  176. * A browser history stores the current location in regular URLs in a web
  177. * browser environment. This is the standard for most web apps and provides the
  178. * cleanest URLs the browser's address bar.
  179. *
  180. * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
  181. */
  182. interface BrowserHistory extends UrlHistory {
  183. }
  184. type BrowserHistoryOptions = UrlHistoryOptions;
  185. /**
  186. * Browser history stores the location in regular URLs. This is the standard for
  187. * most web apps, but it requires some configuration on the server to ensure you
  188. * serve the same app at multiple URLs.
  189. *
  190. * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
  191. */
  192. declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
  193. /**
  194. * @private
  195. */
  196. declare function invariant(value: boolean, message?: string): asserts value;
  197. declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
  198. /**
  199. * Creates a string URL path from the given pathname, search, and hash components.
  200. *
  201. * @category Utils
  202. */
  203. declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
  204. /**
  205. * Parses a string URL path into its separate pathname, search, and hash components.
  206. *
  207. * @category Utils
  208. */
  209. declare function parsePath(path: string): Partial<Path>;
  210. interface UrlHistory extends History {
  211. }
  212. type UrlHistoryOptions = {
  213. window?: Window;
  214. v5Compat?: boolean;
  215. };
  216. type MaybePromise<T> = T | Promise<T>;
  217. /**
  218. * Map of routeId -> data returned from a loader/action/error
  219. */
  220. interface RouteData {
  221. [routeId: string]: any;
  222. }
  223. type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
  224. type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
  225. /**
  226. * Users can specify either lowercase or uppercase form methods on `<Form>`,
  227. * useSubmit(), `<fetcher.Form>`, etc.
  228. */
  229. type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
  230. /**
  231. * Active navigation/fetcher form methods are exposed in uppercase on the
  232. * RouterState. This is to align with the normalization done via fetch().
  233. */
  234. type FormMethod = UpperCaseFormMethod;
  235. type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
  236. type JsonObject = {
  237. [Key in string]: JsonValue;
  238. } & {
  239. [Key in string]?: JsonValue | undefined;
  240. };
  241. type JsonArray = JsonValue[] | readonly JsonValue[];
  242. type JsonPrimitive = string | number | boolean | null;
  243. type JsonValue = JsonPrimitive | JsonObject | JsonArray;
  244. /**
  245. * @private
  246. * Internal interface to pass around for action submissions, not intended for
  247. * external consumption
  248. */
  249. type Submission = {
  250. formMethod: FormMethod;
  251. formAction: string;
  252. formEncType: FormEncType;
  253. formData: FormData;
  254. json: undefined;
  255. text: undefined;
  256. } | {
  257. formMethod: FormMethod;
  258. formAction: string;
  259. formEncType: FormEncType;
  260. formData: undefined;
  261. json: JsonValue;
  262. text: undefined;
  263. } | {
  264. formMethod: FormMethod;
  265. formAction: string;
  266. formEncType: FormEncType;
  267. formData: undefined;
  268. json: undefined;
  269. text: string;
  270. };
  271. /**
  272. * A context instance used as the key for the `get`/`set` methods of a
  273. * {@link RouterContextProvider}. Accepts an optional default
  274. * value to be returned if no value has been set.
  275. */
  276. interface RouterContext<T = unknown> {
  277. defaultValue?: T;
  278. }
  279. /**
  280. * Creates a type-safe {@link RouterContext} object that can be used to
  281. * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
  282. * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
  283. * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
  284. * but specifically designed for React Router's request/response lifecycle.
  285. *
  286. * If a `defaultValue` is provided, it will be returned from `context.get()`
  287. * when no value has been set for the context. Otherwise, reading this context
  288. * when no value has been set will throw an error.
  289. *
  290. * ```tsx filename=app/context.ts
  291. * import { createContext } from "react-router";
  292. *
  293. * // Create a context for user data
  294. * export const userContext =
  295. * createContext<User | null>(null);
  296. * ```
  297. *
  298. * ```tsx filename=app/middleware/auth.ts
  299. * import { getUserFromSession } from "~/auth.server";
  300. * import { userContext } from "~/context";
  301. *
  302. * export const authMiddleware = async ({
  303. * context,
  304. * request,
  305. * }) => {
  306. * const user = await getUserFromSession(request);
  307. * context.set(userContext, user);
  308. * };
  309. * ```
  310. *
  311. * ```tsx filename=app/routes/profile.tsx
  312. * import { userContext } from "~/context";
  313. *
  314. * export async function loader({
  315. * context,
  316. * }: Route.LoaderArgs) {
  317. * const user = context.get(userContext);
  318. *
  319. * if (!user) {
  320. * throw new Response("Unauthorized", { status: 401 });
  321. * }
  322. *
  323. * return { user };
  324. * }
  325. * ```
  326. *
  327. * @public
  328. * @category Utils
  329. * @mode framework
  330. * @mode data
  331. * @param defaultValue An optional default value for the context. This value
  332. * will be returned if no value has been set for this context.
  333. * @returns A {@link RouterContext} object that can be used with
  334. * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
  335. * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
  336. */
  337. declare function createContext<T>(defaultValue?: T): RouterContext<T>;
  338. /**
  339. * Provides methods for writing/reading values in application context in a
  340. * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
  341. *
  342. * @example
  343. * import {
  344. * createContext,
  345. * RouterContextProvider
  346. * } from "react-router";
  347. *
  348. * const userContext = createContext<User | null>(null);
  349. * const contextProvider = new RouterContextProvider();
  350. * contextProvider.set(userContext, getUser());
  351. * // ^ Type-safe
  352. * const user = contextProvider.get(userContext);
  353. * // ^ User
  354. *
  355. * @public
  356. * @category Utils
  357. * @mode framework
  358. * @mode data
  359. */
  360. declare class RouterContextProvider {
  361. #private;
  362. /**
  363. * Create a new `RouterContextProvider` instance
  364. * @param init An optional initial context map to populate the provider with
  365. */
  366. constructor(init?: Map<RouterContext, unknown>);
  367. /**
  368. * Access a value from the context. If no value has been set for the context,
  369. * it will return the context's `defaultValue` if provided, or throw an error
  370. * if no `defaultValue` was set.
  371. * @param context The context to get the value for
  372. * @returns The value for the context, or the context's `defaultValue` if no
  373. * value was set
  374. */
  375. get<T>(context: RouterContext<T>): T;
  376. /**
  377. * Set a value for the context. If the context already has a value set, this
  378. * will overwrite it.
  379. *
  380. * @param context The context to set the value for
  381. * @param value The value to set for the context
  382. * @returns {void}
  383. */
  384. set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void;
  385. }
  386. type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : any;
  387. /**
  388. * @private
  389. * Arguments passed to route loader/action functions. Same for now but we keep
  390. * this as a private implementation detail in case they diverge in the future.
  391. */
  392. interface DataFunctionArgs<Context> {
  393. /** 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. */
  394. request: Request;
  395. /**
  396. * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
  397. * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
  398. */
  399. unstable_pattern: string;
  400. /**
  401. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
  402. * @example
  403. * // app/routes.ts
  404. * route("teams/:teamId", "./team.tsx"),
  405. *
  406. * // app/team.tsx
  407. * export function loader({
  408. * params,
  409. * }: Route.LoaderArgs) {
  410. * params.teamId;
  411. * // ^ string
  412. * }
  413. */
  414. params: Params;
  415. /**
  416. * This is the context passed in to your server adapter's getLoadContext() function.
  417. * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
  418. * It is only applicable if you are using a custom server adapter.
  419. */
  420. context: Context;
  421. }
  422. /**
  423. * Route middleware `next` function to call downstream handlers and then complete
  424. * middlewares from the bottom-up
  425. */
  426. interface MiddlewareNextFunction<Result = unknown> {
  427. (): Promise<Result>;
  428. }
  429. /**
  430. * Route middleware function signature. Receives the same "data" arguments as a
  431. * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
  432. * a `next` function as the second parameter which will call downstream handlers
  433. * and then complete middlewares from the bottom-up
  434. */
  435. type MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<RouterContextProvider>>, next: MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
  436. /**
  437. * Arguments passed to loader functions
  438. */
  439. interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
  440. }
  441. /**
  442. * Arguments passed to action functions
  443. */
  444. interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
  445. }
  446. /**
  447. * Loaders and actions can return anything
  448. */
  449. type DataFunctionValue = unknown;
  450. type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
  451. /**
  452. * Route loader function signature
  453. */
  454. type LoaderFunction<Context = DefaultContext> = {
  455. (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
  456. } & {
  457. hydrate?: boolean;
  458. };
  459. /**
  460. * Route action function signature
  461. */
  462. interface ActionFunction<Context = DefaultContext> {
  463. (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
  464. }
  465. /**
  466. * Arguments passed to shouldRevalidate function
  467. */
  468. interface ShouldRevalidateFunctionArgs {
  469. /** 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. */
  470. currentUrl: URL;
  471. /** 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. */
  472. currentParams: AgnosticDataRouteMatch["params"];
  473. /** 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. */
  474. nextUrl: URL;
  475. /** 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. */
  476. nextParams: AgnosticDataRouteMatch["params"];
  477. /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
  478. formMethod?: Submission["formMethod"];
  479. /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
  480. formAction?: Submission["formAction"];
  481. /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
  482. formEncType?: Submission["formEncType"];
  483. /** The form submission data when the form's encType is `text/plain` */
  484. text?: Submission["text"];
  485. /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
  486. formData?: Submission["formData"];
  487. /** The form submission data when the form's encType is `application/json` */
  488. json?: Submission["json"];
  489. /** The status code of the action response */
  490. actionStatus?: number;
  491. /**
  492. * 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.
  493. *
  494. * @example
  495. * export async function action() {
  496. * await saveSomeStuff();
  497. * return { ok: true };
  498. * }
  499. *
  500. * export function shouldRevalidate({
  501. * actionResult,
  502. * }) {
  503. * if (actionResult?.ok) {
  504. * return false;
  505. * }
  506. * return true;
  507. * }
  508. */
  509. actionResult?: any;
  510. /**
  511. * 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:
  512. *
  513. * /projects/123/tasks/abc
  514. * /projects/123/tasks/def
  515. * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
  516. *
  517. * 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.
  518. */
  519. defaultShouldRevalidate: boolean;
  520. }
  521. /**
  522. * Route shouldRevalidate function signature. This runs after any submission
  523. * (navigation or fetcher), so we flatten the navigation/fetcher submission
  524. * onto the arguments. It shouldn't matter whether it came from a navigation
  525. * or a fetcher, what really matters is the URLs and the formData since loaders
  526. * have to re-run based on the data models that were potentially mutated.
  527. */
  528. interface ShouldRevalidateFunction {
  529. (args: ShouldRevalidateFunctionArgs): boolean;
  530. }
  531. interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
  532. /**
  533. * @private
  534. */
  535. _lazyPromises?: {
  536. middleware: Promise<void> | undefined;
  537. handler: Promise<void> | undefined;
  538. route: Promise<void> | undefined;
  539. };
  540. /**
  541. * @deprecated Deprecated in favor of `shouldCallHandler`
  542. *
  543. * A boolean value indicating whether this route handler should be called in
  544. * this pass.
  545. *
  546. * The `matches` array always includes _all_ matched routes even when only
  547. * _some_ route handlers need to be called so that things like middleware can
  548. * be implemented.
  549. *
  550. * `shouldLoad` is usually only interesting if you are skipping the route
  551. * handler entirely and implementing custom handler logic - since it lets you
  552. * determine if that custom logic should run for this route or not.
  553. *
  554. * For example:
  555. * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
  556. * you'll get an array of three matches (`[parent, child, b]`), but only `b`
  557. * will have `shouldLoad=true` because the data for `parent` and `child` is
  558. * already loaded
  559. * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
  560. * then only `a` will have `shouldLoad=true` for the action execution of
  561. * `dataStrategy`
  562. * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
  563. * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
  564. * revalidation, and all matches will have `shouldLoad=true` (assuming no
  565. * custom `shouldRevalidate` implementations)
  566. */
  567. shouldLoad: boolean;
  568. /**
  569. * Arguments passed to the `shouldRevalidate` function for this `loader` execution.
  570. * Will be `null` if this is not a revalidating loader {@link DataStrategyMatch}.
  571. */
  572. shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
  573. /**
  574. * Determine if this route's handler should be called during this `dataStrategy`
  575. * execution. Calling it with no arguments will leverage the default revalidation
  576. * behavior. You can pass your own `defaultShouldRevalidate` value if you wish
  577. * to change the default revalidation behavior with your `dataStrategy`.
  578. *
  579. * @param defaultShouldRevalidate `defaultShouldRevalidate` override value (optional)
  580. */
  581. shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
  582. /**
  583. * An async function that will resolve any `route.lazy` implementations and
  584. * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
  585. *
  586. * - Calling `match.resolve` does not mean you're calling the
  587. * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
  588. * (the "handler") - `resolve` will only call the `handler` internally if
  589. * needed _and_ if you don't pass your own `handlerOverride` function parameter
  590. * - It is safe to call `match.resolve` for all matches, even if they have
  591. * `shouldLoad=false`, and it will no-op if no loading is required
  592. * - You should generally always call `match.resolve()` for `shouldLoad:true`
  593. * routes to ensure that any `route.lazy` implementations are processed
  594. * - See the examples below for how to implement custom handler execution via
  595. * `match.resolve`
  596. */
  597. resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
  598. }
  599. interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
  600. /**
  601. * Matches for this route extended with Data strategy APIs
  602. */
  603. matches: DataStrategyMatch[];
  604. runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
  605. /**
  606. * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
  607. * for navigational executions
  608. */
  609. fetcherKey: string | null;
  610. }
  611. /**
  612. * Result from a loader or action called via dataStrategy
  613. */
  614. interface DataStrategyResult {
  615. type: "data" | "error";
  616. result: unknown;
  617. }
  618. interface DataStrategyFunction<Context = DefaultContext> {
  619. (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
  620. }
  621. type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
  622. signal: AbortSignal;
  623. path: string;
  624. matches: M[];
  625. fetcherKey: string | undefined;
  626. patch: (routeId: string | null, children: O[]) => void;
  627. };
  628. type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => MaybePromise<void>;
  629. /**
  630. * Function provided by the framework-aware layers to set any framework-specific
  631. * properties from framework-agnostic properties
  632. */
  633. interface MapRoutePropertiesFunction {
  634. (route: AgnosticDataRouteObject): {
  635. hasErrorBoundary: boolean;
  636. } & Record<string, any>;
  637. }
  638. /**
  639. * Keys we cannot change from within a lazy object. We spread all other keys
  640. * onto the route. Either they're meaningful to the router, or they'll get
  641. * ignored.
  642. */
  643. type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
  644. /**
  645. * Keys we cannot change from within a lazy() function. We spread all other keys
  646. * onto the route. Either they're meaningful to the router, or they'll get
  647. * ignored.
  648. */
  649. type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "middleware";
  650. /**
  651. * lazy object to load route properties, which can add non-matching
  652. * related properties to a route
  653. */
  654. type LazyRouteObject<R extends AgnosticRouteObject> = {
  655. [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
  656. };
  657. /**
  658. * lazy() function to load a route definition, which can add non-matching
  659. * related properties to a route
  660. */
  661. interface LazyRouteFunction<R extends AgnosticRouteObject> {
  662. (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
  663. }
  664. type LazyRouteDefinition<R extends AgnosticRouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
  665. /**
  666. * Base RouteObject with common props shared by all types of routes
  667. */
  668. type AgnosticBaseRouteObject = {
  669. caseSensitive?: boolean;
  670. path?: string;
  671. id?: string;
  672. middleware?: MiddlewareFunction[];
  673. loader?: LoaderFunction | boolean;
  674. action?: ActionFunction | boolean;
  675. hasErrorBoundary?: boolean;
  676. shouldRevalidate?: ShouldRevalidateFunction;
  677. handle?: any;
  678. lazy?: LazyRouteDefinition<AgnosticBaseRouteObject>;
  679. };
  680. /**
  681. * Index routes must not have children
  682. */
  683. type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
  684. children?: undefined;
  685. index: true;
  686. };
  687. /**
  688. * Non-index routes may have children, but cannot have index
  689. */
  690. type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
  691. children?: AgnosticRouteObject[];
  692. index?: false;
  693. };
  694. /**
  695. * A route object represents a logical route, with (optionally) its child
  696. * routes organized in a tree-like structure.
  697. */
  698. type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
  699. type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
  700. id: string;
  701. };
  702. type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
  703. children?: AgnosticDataRouteObject[];
  704. id: string;
  705. };
  706. /**
  707. * A data route object, which is just a RouteObject with a required unique ID
  708. */
  709. type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
  710. type RouteManifest<R = AgnosticDataRouteObject> = Record<string, R | undefined>;
  711. type Regex_az = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
  712. type Regez_AZ = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
  713. type Regex_09 = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
  714. type Regex_w = Regex_az | Regez_AZ | Regex_09 | "_";
  715. type ParamChar = Regex_w | "-";
  716. type RegexMatchPlus<CharPattern extends string, T extends string> = T extends `${infer First}${infer Rest}` ? First extends CharPattern ? RegexMatchPlus<CharPattern, Rest> extends never ? First : `${First}${RegexMatchPlus<CharPattern, Rest>}` : never : never;
  717. type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?${string}` ? RegexMatchPlus<ParamChar, Optional> : RegexMatchPlus<ParamChar, Param> : never;
  718. type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
  719. type ParamParseKey<Segment extends string> = [
  720. PathParam<Segment>
  721. ] extends [never] ? string : PathParam<Segment>;
  722. /**
  723. * The parameters that were parsed from the URL path.
  724. */
  725. type Params<Key extends string = string> = {
  726. readonly [key in Key]: string | undefined;
  727. };
  728. /**
  729. * A RouteMatch contains info about how a route matched a URL.
  730. */
  731. interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
  732. /**
  733. * The names and values of dynamic parameters in the URL.
  734. */
  735. params: Params<ParamKey>;
  736. /**
  737. * The portion of the URL pathname that was matched.
  738. */
  739. pathname: string;
  740. /**
  741. * The portion of the URL pathname that was matched before child routes.
  742. */
  743. pathnameBase: string;
  744. /**
  745. * The route object that was used to match.
  746. */
  747. route: RouteObjectType;
  748. }
  749. interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
  750. }
  751. /**
  752. * Matches the given routes to a location and returns the match data.
  753. *
  754. * @example
  755. * import { matchRoutes } from "react-router";
  756. *
  757. * let routes = [{
  758. * path: "/",
  759. * Component: Root,
  760. * children: [{
  761. * path: "dashboard",
  762. * Component: Dashboard,
  763. * }]
  764. * }];
  765. *
  766. * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
  767. *
  768. * @public
  769. * @category Utils
  770. * @param routes The array of route objects to match against.
  771. * @param locationArg The location to match against, either a string path or a
  772. * partial {@link Location} object
  773. * @param basename Optional base path to strip from the location before matching.
  774. * Defaults to `/`.
  775. * @returns An array of matched routes, or `null` if no matches were found.
  776. */
  777. declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
  778. interface UIMatch<Data = unknown, Handle = unknown> {
  779. id: string;
  780. pathname: string;
  781. /**
  782. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
  783. */
  784. params: AgnosticRouteMatch["params"];
  785. /**
  786. * The return value from the matched route's loader or clientLoader. This might
  787. * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
  788. * an error and we're currently displaying an `ErrorBoundary`.
  789. *
  790. * @deprecated Use `UIMatch.loaderData` instead
  791. */
  792. data: Data | undefined;
  793. /**
  794. * The return value from the matched route's loader or clientLoader. This might
  795. * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
  796. * an error and we're currently displaying an `ErrorBoundary`.
  797. */
  798. loaderData: Data | undefined;
  799. /**
  800. * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
  801. * exported from the matched route module
  802. */
  803. handle: Handle;
  804. }
  805. /**
  806. * Returns a path with params interpolated.
  807. *
  808. * @example
  809. * import { generatePath } from "react-router";
  810. *
  811. * generatePath("/users/:id", { id: "123" }); // "/users/123"
  812. *
  813. * @public
  814. * @category Utils
  815. * @param originalPath The original path to generate.
  816. * @param params The parameters to interpolate into the path.
  817. * @returns The generated path with parameters interpolated.
  818. */
  819. declare function generatePath<Path extends string>(originalPath: Path, params?: {
  820. [key in PathParam<Path>]: string | null;
  821. }): string;
  822. /**
  823. * Used to match on some portion of a URL pathname.
  824. */
  825. interface PathPattern<Path extends string = string> {
  826. /**
  827. * A string to match against a URL pathname. May contain `:id`-style segments
  828. * to indicate placeholders for dynamic parameters. It May also end with `/*`
  829. * to indicate matching the rest of the URL pathname.
  830. */
  831. path: Path;
  832. /**
  833. * Should be `true` if the static portions of the `path` should be matched in
  834. * the same case.
  835. */
  836. caseSensitive?: boolean;
  837. /**
  838. * Should be `true` if this pattern should match the entire URL pathname.
  839. */
  840. end?: boolean;
  841. }
  842. /**
  843. * Contains info about how a {@link PathPattern} matched on a URL pathname.
  844. */
  845. interface PathMatch<ParamKey extends string = string> {
  846. /**
  847. * The names and values of dynamic parameters in the URL.
  848. */
  849. params: Params<ParamKey>;
  850. /**
  851. * The portion of the URL pathname that was matched.
  852. */
  853. pathname: string;
  854. /**
  855. * The portion of the URL pathname that was matched before child routes.
  856. */
  857. pathnameBase: string;
  858. /**
  859. * The pattern that was used to match.
  860. */
  861. pattern: PathPattern;
  862. }
  863. /**
  864. * Performs pattern matching on a URL pathname and returns information about
  865. * the match.
  866. *
  867. * @public
  868. * @category Utils
  869. * @param pattern The pattern to match against the URL pathname. This can be a
  870. * string or a {@link PathPattern} object. If a string is provided, it will be
  871. * treated as a pattern with `caseSensitive` set to `false` and `end` set to
  872. * `true`.
  873. * @param pathname The URL pathname to match against the pattern.
  874. * @returns A path match object if the pattern matches the pathname,
  875. * or `null` if it does not match.
  876. */
  877. declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
  878. /**
  879. * Returns a resolved {@link Path} object relative to the given pathname.
  880. *
  881. * @public
  882. * @category Utils
  883. * @param to The path to resolve, either a string or a partial {@link Path}
  884. * object.
  885. * @param fromPathname The pathname to resolve the path from. Defaults to `/`.
  886. * @returns A {@link Path} object with the resolved pathname, search, and hash.
  887. */
  888. declare function resolvePath(to: To, fromPathname?: string): Path;
  889. declare class DataWithResponseInit<D> {
  890. type: string;
  891. data: D;
  892. init: ResponseInit | null;
  893. constructor(data: D, init?: ResponseInit);
  894. }
  895. /**
  896. * Create "responses" that contain `headers`/`status` without forcing
  897. * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  898. *
  899. * @example
  900. * import { data } from "react-router";
  901. *
  902. * export async function action({ request }: Route.ActionArgs) {
  903. * let formData = await request.formData();
  904. * let item = await createItem(formData);
  905. * return data(item, {
  906. * headers: { "X-Custom-Header": "value" }
  907. * status: 201,
  908. * });
  909. * }
  910. *
  911. * @public
  912. * @category Utils
  913. * @mode framework
  914. * @mode data
  915. * @param data The data to be included in the response.
  916. * @param init The status code or a `ResponseInit` object to be included in the
  917. * response.
  918. * @returns A {@link DataWithResponseInit} instance containing the data and
  919. * response init.
  920. */
  921. declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
  922. interface TrackedPromise extends Promise<any> {
  923. _tracked?: boolean;
  924. _data?: any;
  925. _error?: any;
  926. }
  927. type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
  928. /**
  929. * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
  930. * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  931. * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
  932. *
  933. * @example
  934. * import { redirect } from "react-router";
  935. *
  936. * export async function loader({ request }: Route.LoaderArgs) {
  937. * if (!isLoggedIn(request))
  938. * throw redirect("/login");
  939. * }
  940. *
  941. * // ...
  942. * }
  943. *
  944. * @public
  945. * @category Utils
  946. * @mode framework
  947. * @mode data
  948. * @param url The URL to redirect to.
  949. * @param init The status code or a `ResponseInit` object to be included in the
  950. * response.
  951. * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  952. * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  953. * header.
  954. */
  955. declare const redirect: RedirectFunction;
  956. /**
  957. * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  958. * that will force a document reload to the new location. Sets the status code
  959. * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  960. * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
  961. *
  962. * ```tsx filename=routes/logout.tsx
  963. * import { redirectDocument } from "react-router";
  964. *
  965. * import { destroySession } from "../sessions.server";
  966. *
  967. * export async function action({ request }: Route.ActionArgs) {
  968. * let session = await getSession(request.headers.get("Cookie"));
  969. * return redirectDocument("/", {
  970. * headers: { "Set-Cookie": await destroySession(session) }
  971. * });
  972. * }
  973. * ```
  974. *
  975. * @public
  976. * @category Utils
  977. * @mode framework
  978. * @mode data
  979. * @param url The URL to redirect to.
  980. * @param init The status code or a `ResponseInit` object to be included in the
  981. * response.
  982. * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  983. * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  984. * header.
  985. */
  986. declare const redirectDocument: RedirectFunction;
  987. /**
  988. * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  989. * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
  990. * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
  991. * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  992. * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
  993. *
  994. * @example
  995. * import { replace } from "react-router";
  996. *
  997. * export async function loader() {
  998. * return replace("/new-location");
  999. * }
  1000. *
  1001. * @public
  1002. * @category Utils
  1003. * @mode framework
  1004. * @mode data
  1005. * @param url The URL to redirect to.
  1006. * @param init The status code or a `ResponseInit` object to be included in the
  1007. * response.
  1008. * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  1009. * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
  1010. * header.
  1011. */
  1012. declare const replace: RedirectFunction;
  1013. type ErrorResponse = {
  1014. status: number;
  1015. statusText: string;
  1016. data: any;
  1017. };
  1018. declare class ErrorResponseImpl implements ErrorResponse {
  1019. status: number;
  1020. statusText: string;
  1021. data: any;
  1022. private error?;
  1023. private internal;
  1024. constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
  1025. }
  1026. /**
  1027. * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
  1028. * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
  1029. * thrown from an [`action`](../../start/framework/route-module#action) or
  1030. * [`loader`](../../start/framework/route-module#loader) function.
  1031. *
  1032. * @example
  1033. * import { isRouteErrorResponse } from "react-router";
  1034. *
  1035. * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
  1036. * if (isRouteErrorResponse(error)) {
  1037. * return (
  1038. * <>
  1039. * <p>Error: `${error.status}: ${error.statusText}`</p>
  1040. * <p>{error.data}</p>
  1041. * </>
  1042. * );
  1043. * }
  1044. *
  1045. * return (
  1046. * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
  1047. * );
  1048. * }
  1049. *
  1050. * @public
  1051. * @category Utils
  1052. * @mode framework
  1053. * @mode data
  1054. * @param error The error to check.
  1055. * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
  1056. */
  1057. declare function isRouteErrorResponse(error: any): error is ErrorResponse;
  1058. /**
  1059. * An object of unknown type for route loaders and actions provided by the
  1060. * server's `getLoadContext()` function. This is defined as an empty interface
  1061. * specifically so apps can leverage declaration merging to augment this type
  1062. * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
  1063. */
  1064. interface AppLoadContext {
  1065. [key: string]: unknown;
  1066. }
  1067. /**
  1068. * A Router instance manages all navigation and data loading/mutations
  1069. */
  1070. interface Router$1 {
  1071. /**
  1072. * @private
  1073. * PRIVATE - DO NOT USE
  1074. *
  1075. * Return the basename for the router
  1076. */
  1077. get basename(): RouterInit["basename"];
  1078. /**
  1079. * @private
  1080. * PRIVATE - DO NOT USE
  1081. *
  1082. * Return the future config for the router
  1083. */
  1084. get future(): FutureConfig;
  1085. /**
  1086. * @private
  1087. * PRIVATE - DO NOT USE
  1088. *
  1089. * Return the current state of the router
  1090. */
  1091. get state(): RouterState;
  1092. /**
  1093. * @private
  1094. * PRIVATE - DO NOT USE
  1095. *
  1096. * Return the routes for this router instance
  1097. */
  1098. get routes(): AgnosticDataRouteObject[];
  1099. /**
  1100. * @private
  1101. * PRIVATE - DO NOT USE
  1102. *
  1103. * Return the window associated with the router
  1104. */
  1105. get window(): RouterInit["window"];
  1106. /**
  1107. * @private
  1108. * PRIVATE - DO NOT USE
  1109. *
  1110. * Initialize the router, including adding history listeners and kicking off
  1111. * initial data fetches. Returns a function to cleanup listeners and abort
  1112. * any in-progress loads
  1113. */
  1114. initialize(): Router$1;
  1115. /**
  1116. * @private
  1117. * PRIVATE - DO NOT USE
  1118. *
  1119. * Subscribe to router.state updates
  1120. *
  1121. * @param fn function to call with the new state
  1122. */
  1123. subscribe(fn: RouterSubscriber): () => void;
  1124. /**
  1125. * @private
  1126. * PRIVATE - DO NOT USE
  1127. *
  1128. * Enable scroll restoration behavior in the router
  1129. *
  1130. * @param savedScrollPositions Object that will manage positions, in case
  1131. * it's being restored from sessionStorage
  1132. * @param getScrollPosition Function to get the active Y scroll position
  1133. * @param getKey Function to get the key to use for restoration
  1134. */
  1135. enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
  1136. /**
  1137. * @private
  1138. * PRIVATE - DO NOT USE
  1139. *
  1140. * Navigate forward/backward in the history stack
  1141. * @param to Delta to move in the history stack
  1142. */
  1143. navigate(to: number): Promise<void>;
  1144. /**
  1145. * Navigate to the given path
  1146. * @param to Path to navigate to
  1147. * @param opts Navigation options (method, submission, etc.)
  1148. */
  1149. navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
  1150. /**
  1151. * @private
  1152. * PRIVATE - DO NOT USE
  1153. *
  1154. * Trigger a fetcher load/submission
  1155. *
  1156. * @param key Fetcher key
  1157. * @param routeId Route that owns the fetcher
  1158. * @param href href to fetch
  1159. * @param opts Fetcher options, (method, submission, etc.)
  1160. */
  1161. fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
  1162. /**
  1163. * @private
  1164. * PRIVATE - DO NOT USE
  1165. *
  1166. * Trigger a revalidation of all current route loaders and fetcher loads
  1167. */
  1168. revalidate(): Promise<void>;
  1169. /**
  1170. * @private
  1171. * PRIVATE - DO NOT USE
  1172. *
  1173. * Utility function to create an href for the given location
  1174. * @param location
  1175. */
  1176. createHref(location: Location | URL): string;
  1177. /**
  1178. * @private
  1179. * PRIVATE - DO NOT USE
  1180. *
  1181. * Utility function to URL encode a destination path according to the internal
  1182. * history implementation
  1183. * @param to
  1184. */
  1185. encodeLocation(to: To): Path;
  1186. /**
  1187. * @private
  1188. * PRIVATE - DO NOT USE
  1189. *
  1190. * Get/create a fetcher for the given key
  1191. * @param key
  1192. */
  1193. getFetcher<TData = any>(key: string): Fetcher<TData>;
  1194. /**
  1195. * @internal
  1196. * PRIVATE - DO NOT USE
  1197. *
  1198. * Reset the fetcher for a given key
  1199. * @param key
  1200. */
  1201. resetFetcher(key: string, opts?: {
  1202. reason?: unknown;
  1203. }): void;
  1204. /**
  1205. * @private
  1206. * PRIVATE - DO NOT USE
  1207. *
  1208. * Delete the fetcher for a given key
  1209. * @param key
  1210. */
  1211. deleteFetcher(key: string): void;
  1212. /**
  1213. * @private
  1214. * PRIVATE - DO NOT USE
  1215. *
  1216. * Cleanup listeners and abort any in-progress loads
  1217. */
  1218. dispose(): void;
  1219. /**
  1220. * @private
  1221. * PRIVATE - DO NOT USE
  1222. *
  1223. * Get a navigation blocker
  1224. * @param key The identifier for the blocker
  1225. * @param fn The blocker function implementation
  1226. */
  1227. getBlocker(key: string, fn: BlockerFunction): Blocker;
  1228. /**
  1229. * @private
  1230. * PRIVATE - DO NOT USE
  1231. *
  1232. * Delete a navigation blocker
  1233. * @param key The identifier for the blocker
  1234. */
  1235. deleteBlocker(key: string): void;
  1236. /**
  1237. * @private
  1238. * PRIVATE DO NOT USE
  1239. *
  1240. * Patch additional children routes into an existing parent route
  1241. * @param routeId The parent route id or a callback function accepting `patch`
  1242. * to perform batch patching
  1243. * @param children The additional children routes
  1244. * @param unstable_allowElementMutations Allow mutation or route elements on
  1245. * existing routes. Intended for RSC-usage
  1246. * only.
  1247. */
  1248. patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
  1249. /**
  1250. * @private
  1251. * PRIVATE - DO NOT USE
  1252. *
  1253. * HMR needs to pass in-flight route updates to React Router
  1254. * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
  1255. */
  1256. _internalSetRoutes(routes: AgnosticRouteObject[]): void;
  1257. /**
  1258. * @private
  1259. * PRIVATE - DO NOT USE
  1260. *
  1261. * Cause subscribers to re-render. This is used to force a re-render.
  1262. */
  1263. _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
  1264. /**
  1265. * @private
  1266. * PRIVATE - DO NOT USE
  1267. *
  1268. * Internal fetch AbortControllers accessed by unit tests
  1269. */
  1270. _internalFetchControllers: Map<string, AbortController>;
  1271. }
  1272. /**
  1273. * State maintained internally by the router. During a navigation, all states
  1274. * reflect the "old" location unless otherwise noted.
  1275. */
  1276. interface RouterState {
  1277. /**
  1278. * The action of the most recent navigation
  1279. */
  1280. historyAction: Action;
  1281. /**
  1282. * The current location reflected by the router
  1283. */
  1284. location: Location;
  1285. /**
  1286. * The current set of route matches
  1287. */
  1288. matches: AgnosticDataRouteMatch[];
  1289. /**
  1290. * Tracks whether we've completed our initial data load
  1291. */
  1292. initialized: boolean;
  1293. /**
  1294. * Current scroll position we should start at for a new view
  1295. * - number -> scroll position to restore to
  1296. * - false -> do not restore scroll at all (used during submissions/revalidations)
  1297. * - null -> don't have a saved position, scroll to hash or top of page
  1298. */
  1299. restoreScrollPosition: number | false | null;
  1300. /**
  1301. * Indicate whether this navigation should skip resetting the scroll position
  1302. * if we are unable to restore the scroll position
  1303. */
  1304. preventScrollReset: boolean;
  1305. /**
  1306. * Tracks the state of the current navigation
  1307. */
  1308. navigation: Navigation;
  1309. /**
  1310. * Tracks any in-progress revalidations
  1311. */
  1312. revalidation: RevalidationState;
  1313. /**
  1314. * Data from the loaders for the current matches
  1315. */
  1316. loaderData: RouteData;
  1317. /**
  1318. * Data from the action for the current matches
  1319. */
  1320. actionData: RouteData | null;
  1321. /**
  1322. * Errors caught from loaders for the current matches
  1323. */
  1324. errors: RouteData | null;
  1325. /**
  1326. * Map of current fetchers
  1327. */
  1328. fetchers: Map<string, Fetcher>;
  1329. /**
  1330. * Map of current blockers
  1331. */
  1332. blockers: Map<string, Blocker>;
  1333. }
  1334. /**
  1335. * Data that can be passed into hydrate a Router from SSR
  1336. */
  1337. type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
  1338. /**
  1339. * Future flags to toggle new feature behavior
  1340. */
  1341. interface FutureConfig {
  1342. }
  1343. /**
  1344. * Initialization options for createRouter
  1345. */
  1346. interface RouterInit {
  1347. routes: AgnosticRouteObject[];
  1348. history: History;
  1349. basename?: string;
  1350. getContext?: () => MaybePromise<RouterContextProvider>;
  1351. unstable_instrumentations?: unstable_ClientInstrumentation[];
  1352. mapRouteProperties?: MapRoutePropertiesFunction;
  1353. future?: Partial<FutureConfig>;
  1354. hydrationRouteProperties?: string[];
  1355. hydrationData?: HydrationState;
  1356. window?: Window;
  1357. dataStrategy?: DataStrategyFunction;
  1358. patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
  1359. }
  1360. /**
  1361. * State returned from a server-side query() call
  1362. */
  1363. interface StaticHandlerContext {
  1364. basename: Router$1["basename"];
  1365. location: RouterState["location"];
  1366. matches: RouterState["matches"];
  1367. loaderData: RouterState["loaderData"];
  1368. actionData: RouterState["actionData"];
  1369. errors: RouterState["errors"];
  1370. statusCode: number;
  1371. loaderHeaders: Record<string, Headers>;
  1372. actionHeaders: Record<string, Headers>;
  1373. _deepestRenderedBoundaryId?: string | null;
  1374. }
  1375. /**
  1376. * A StaticHandler instance manages a singular SSR navigation/fetch event
  1377. */
  1378. interface StaticHandler {
  1379. dataRoutes: AgnosticDataRouteObject[];
  1380. query(request: Request, opts?: {
  1381. requestContext?: unknown;
  1382. filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
  1383. skipLoaderErrorBubbling?: boolean;
  1384. skipRevalidation?: boolean;
  1385. dataStrategy?: DataStrategyFunction<unknown>;
  1386. generateMiddlewareResponse?: (query: (r: Request, args?: {
  1387. filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
  1388. }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
  1389. }): Promise<StaticHandlerContext | Response>;
  1390. queryRoute(request: Request, opts?: {
  1391. routeId?: string;
  1392. requestContext?: unknown;
  1393. dataStrategy?: DataStrategyFunction<unknown>;
  1394. generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
  1395. }): Promise<any>;
  1396. }
  1397. type ViewTransitionOpts = {
  1398. currentLocation: Location;
  1399. nextLocation: Location;
  1400. };
  1401. /**
  1402. * Subscriber function signature for changes to router state
  1403. */
  1404. interface RouterSubscriber {
  1405. (state: RouterState, opts: {
  1406. deletedFetchers: string[];
  1407. newErrors: RouteData | null;
  1408. viewTransitionOpts?: ViewTransitionOpts;
  1409. flushSync: boolean;
  1410. }): void;
  1411. }
  1412. /**
  1413. * Function signature for determining the key to be used in scroll restoration
  1414. * for a given location
  1415. */
  1416. interface GetScrollRestorationKeyFunction {
  1417. (location: Location, matches: UIMatch[]): string | null;
  1418. }
  1419. /**
  1420. * Function signature for determining the current scroll position
  1421. */
  1422. interface GetScrollPositionFunction {
  1423. (): number;
  1424. }
  1425. /**
  1426. * - "route": relative to the route hierarchy so `..` means remove all segments
  1427. * of the current route even if it has many. For example, a `route("posts/:id")`
  1428. * would have both `:id` and `posts` removed from the url.
  1429. * - "path": relative to the pathname so `..` means remove one segment of the
  1430. * pathname. For example, a `route("posts/:id")` would have only `:id` removed
  1431. * from the url.
  1432. */
  1433. type RelativeRoutingType = "route" | "path";
  1434. type BaseNavigateOrFetchOptions = {
  1435. preventScrollReset?: boolean;
  1436. relative?: RelativeRoutingType;
  1437. flushSync?: boolean;
  1438. };
  1439. type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
  1440. replace?: boolean;
  1441. state?: any;
  1442. fromRouteId?: string;
  1443. viewTransition?: boolean;
  1444. };
  1445. type BaseSubmissionOptions = {
  1446. formMethod?: HTMLFormMethod;
  1447. formEncType?: FormEncType;
  1448. } & ({
  1449. formData: FormData;
  1450. body?: undefined;
  1451. } | {
  1452. formData?: undefined;
  1453. body: any;
  1454. });
  1455. /**
  1456. * Options for a navigate() call for a normal (non-submission) navigation
  1457. */
  1458. type LinkNavigateOptions = BaseNavigateOptions;
  1459. /**
  1460. * Options for a navigate() call for a submission navigation
  1461. */
  1462. type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
  1463. /**
  1464. * Options to pass to navigate() for a navigation
  1465. */
  1466. type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
  1467. /**
  1468. * Options for a fetch() load
  1469. */
  1470. type LoadFetchOptions = BaseNavigateOrFetchOptions;
  1471. /**
  1472. * Options for a fetch() submission
  1473. */
  1474. type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
  1475. /**
  1476. * Options to pass to fetch()
  1477. */
  1478. type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
  1479. /**
  1480. * Potential states for state.navigation
  1481. */
  1482. type NavigationStates = {
  1483. Idle: {
  1484. state: "idle";
  1485. location: undefined;
  1486. formMethod: undefined;
  1487. formAction: undefined;
  1488. formEncType: undefined;
  1489. formData: undefined;
  1490. json: undefined;
  1491. text: undefined;
  1492. };
  1493. Loading: {
  1494. state: "loading";
  1495. location: Location;
  1496. formMethod: Submission["formMethod"] | undefined;
  1497. formAction: Submission["formAction"] | undefined;
  1498. formEncType: Submission["formEncType"] | undefined;
  1499. formData: Submission["formData"] | undefined;
  1500. json: Submission["json"] | undefined;
  1501. text: Submission["text"] | undefined;
  1502. };
  1503. Submitting: {
  1504. state: "submitting";
  1505. location: Location;
  1506. formMethod: Submission["formMethod"];
  1507. formAction: Submission["formAction"];
  1508. formEncType: Submission["formEncType"];
  1509. formData: Submission["formData"];
  1510. json: Submission["json"];
  1511. text: Submission["text"];
  1512. };
  1513. };
  1514. type Navigation = NavigationStates[keyof NavigationStates];
  1515. type RevalidationState = "idle" | "loading";
  1516. /**
  1517. * Potential states for fetchers
  1518. */
  1519. type FetcherStates<TData = any> = {
  1520. /**
  1521. * The fetcher is not calling a loader or action
  1522. *
  1523. * ```tsx
  1524. * fetcher.state === "idle"
  1525. * ```
  1526. */
  1527. Idle: {
  1528. state: "idle";
  1529. formMethod: undefined;
  1530. formAction: undefined;
  1531. formEncType: undefined;
  1532. text: undefined;
  1533. formData: undefined;
  1534. json: undefined;
  1535. /**
  1536. * If the fetcher has never been called, this will be undefined.
  1537. */
  1538. data: TData | undefined;
  1539. };
  1540. /**
  1541. * The fetcher is loading data from a {@link LoaderFunction | loader} from a
  1542. * call to {@link FetcherWithComponents.load | `fetcher.load`}.
  1543. *
  1544. * ```tsx
  1545. * // somewhere
  1546. * <button onClick={() => fetcher.load("/some/route") }>Load</button>
  1547. *
  1548. * // the state will update
  1549. * fetcher.state === "loading"
  1550. * ```
  1551. */
  1552. Loading: {
  1553. state: "loading";
  1554. formMethod: Submission["formMethod"] | undefined;
  1555. formAction: Submission["formAction"] | undefined;
  1556. formEncType: Submission["formEncType"] | undefined;
  1557. text: Submission["text"] | undefined;
  1558. formData: Submission["formData"] | undefined;
  1559. json: Submission["json"] | undefined;
  1560. data: TData | undefined;
  1561. };
  1562. /**
  1563. 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`}.
  1564. ```tsx
  1565. // somewhere
  1566. <input
  1567. onChange={e => {
  1568. fetcher.submit(event.currentTarget.form, { method: "post" });
  1569. }}
  1570. />
  1571. // the state will update
  1572. fetcher.state === "submitting"
  1573. // and formData will be available
  1574. fetcher.formData
  1575. ```
  1576. */
  1577. Submitting: {
  1578. state: "submitting";
  1579. formMethod: Submission["formMethod"];
  1580. formAction: Submission["formAction"];
  1581. formEncType: Submission["formEncType"];
  1582. text: Submission["text"];
  1583. formData: Submission["formData"];
  1584. json: Submission["json"];
  1585. data: TData | undefined;
  1586. };
  1587. };
  1588. type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
  1589. interface BlockerBlocked {
  1590. state: "blocked";
  1591. reset: () => void;
  1592. proceed: () => void;
  1593. location: Location;
  1594. }
  1595. interface BlockerUnblocked {
  1596. state: "unblocked";
  1597. reset: undefined;
  1598. proceed: undefined;
  1599. location: undefined;
  1600. }
  1601. interface BlockerProceeding {
  1602. state: "proceeding";
  1603. reset: undefined;
  1604. proceed: undefined;
  1605. location: Location;
  1606. }
  1607. type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
  1608. type BlockerFunction = (args: {
  1609. currentLocation: Location;
  1610. nextLocation: Location;
  1611. historyAction: Action;
  1612. }) => boolean;
  1613. declare const IDLE_NAVIGATION: NavigationStates["Idle"];
  1614. declare const IDLE_FETCHER: FetcherStates["Idle"];
  1615. declare const IDLE_BLOCKER: BlockerUnblocked;
  1616. /**
  1617. * Create a router and listen to history POP navigations
  1618. */
  1619. declare function createRouter(init: RouterInit): Router$1;
  1620. interface CreateStaticHandlerOptions {
  1621. basename?: string;
  1622. mapRouteProperties?: MapRoutePropertiesFunction;
  1623. unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
  1624. future?: {};
  1625. }
  1626. declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
  1627. hasErrorBoundary: boolean;
  1628. };
  1629. declare const hydrationRouteProperties: (keyof RouteObject)[];
  1630. /**
  1631. * @category Data Routers
  1632. */
  1633. interface MemoryRouterOpts {
  1634. /**
  1635. * Basename path for the application.
  1636. */
  1637. basename?: string;
  1638. /**
  1639. * A function that returns an {@link RouterContextProvider} instance
  1640. * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
  1641. * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
  1642. * This function is called to generate a fresh `context` instance on each
  1643. * navigation or fetcher call.
  1644. */
  1645. getContext?: RouterInit["getContext"];
  1646. /**
  1647. * Future flags to enable for the router.
  1648. */
  1649. future?: Partial<FutureConfig>;
  1650. /**
  1651. * Hydration data to initialize the router with if you have already performed
  1652. * data loading on the server.
  1653. */
  1654. hydrationData?: HydrationState;
  1655. /**
  1656. * Initial entries in the in-memory history stack
  1657. */
  1658. initialEntries?: InitialEntry[];
  1659. /**
  1660. * Index of `initialEntries` the application should initialize to
  1661. */
  1662. initialIndex?: number;
  1663. /**
  1664. * Array of instrumentation objects allowing you to instrument the router and
  1665. * individual routes prior to router initialization (and on any subsequently
  1666. * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
  1667. * mostly useful for observability such as wrapping navigations, fetches,
  1668. * as well as route loaders/actions/middlewares with logging and/or performance
  1669. * tracing. See the [docs](../../how-to/instrumentation) for more information.
  1670. *
  1671. * ```tsx
  1672. * let router = createBrowserRouter(routes, {
  1673. * unstable_instrumentations: [logging]
  1674. * });
  1675. *
  1676. *
  1677. * let logging = {
  1678. * router({ instrument }) {
  1679. * instrument({
  1680. * navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
  1681. * fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
  1682. * });
  1683. * },
  1684. * route({ instrument, id }) {
  1685. * instrument({
  1686. * middleware: (impl, info) => logExecution(
  1687. * `middleware ${info.request.url} (route ${id})`,
  1688. * impl
  1689. * ),
  1690. * loader: (impl, info) => logExecution(
  1691. * `loader ${info.request.url} (route ${id})`,
  1692. * impl
  1693. * ),
  1694. * action: (impl, info) => logExecution(
  1695. * `action ${info.request.url} (route ${id})`,
  1696. * impl
  1697. * ),
  1698. * })
  1699. * }
  1700. * };
  1701. *
  1702. * async function logExecution(label: string, impl: () => Promise<void>) {
  1703. * let start = performance.now();
  1704. * console.log(`start ${label}`);
  1705. * await impl();
  1706. * let duration = Math.round(performance.now() - start);
  1707. * console.log(`end ${label} (${duration}ms)`);
  1708. * }
  1709. * ```
  1710. */
  1711. unstable_instrumentations?: unstable_ClientInstrumentation[];
  1712. /**
  1713. * Override the default data strategy of running loaders in parallel -
  1714. * see the [docs](../../how-to/data-strategy) for more information.
  1715. *
  1716. * ```tsx
  1717. * let router = createBrowserRouter(routes, {
  1718. * async dataStrategy({
  1719. * matches,
  1720. * request,
  1721. * runClientMiddleware,
  1722. * }) {
  1723. * const matchesToLoad = matches.filter((m) =>
  1724. * m.shouldCallHandler(),
  1725. * );
  1726. *
  1727. * const results: Record<string, DataStrategyResult> = {};
  1728. * await runClientMiddleware(() =>
  1729. * Promise.all(
  1730. * matchesToLoad.map(async (match) => {
  1731. * results[match.route.id] = await match.resolve();
  1732. * }),
  1733. * ),
  1734. * );
  1735. * return results;
  1736. * },
  1737. * });
  1738. * ```
  1739. */
  1740. dataStrategy?: DataStrategyFunction;
  1741. /**
  1742. * Lazily define portions of the route tree on navigations.
  1743. */
  1744. patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
  1745. }
  1746. /**
  1747. * Create a new {@link DataRouter} that manages the application path using an
  1748. * in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
  1749. * stack. Useful for non-browser environments without a DOM API.
  1750. *
  1751. * @public
  1752. * @category Data Routers
  1753. * @mode data
  1754. * @param routes Application routes
  1755. * @param opts Options
  1756. * @param {MemoryRouterOpts.basename} opts.basename n/a
  1757. * @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
  1758. * @param {MemoryRouterOpts.future} opts.future n/a
  1759. * @param {MemoryRouterOpts.getContext} opts.getContext n/a
  1760. * @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
  1761. * @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
  1762. * @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
  1763. * @param {MemoryRouterOpts.unstable_instrumentations} opts.unstable_instrumentations n/a
  1764. * @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
  1765. * @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
  1766. */
  1767. declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router$1;
  1768. /**
  1769. * Function signature for client side error handling for loader/actions errors
  1770. * and rendering errors via `componentDidCatch`
  1771. */
  1772. interface unstable_ClientOnErrorFunction {
  1773. (error: unknown, info: {
  1774. location: Location;
  1775. params: Params;
  1776. unstable_pattern: string;
  1777. errorInfo?: React.ErrorInfo;
  1778. }): void;
  1779. }
  1780. /**
  1781. * @category Types
  1782. */
  1783. interface RouterProviderProps {
  1784. /**
  1785. * The {@link DataRouter} instance to use for navigation and data fetching.
  1786. */
  1787. router: Router$1;
  1788. /**
  1789. * The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
  1790. * implementation to use for flushing updates.
  1791. *
  1792. * You usually don't have to worry about this:
  1793. * - The `RouterProvider` exported from `react-router/dom` handles this internally for you
  1794. * - If you are rendering in a non-DOM environment, you can import
  1795. * `RouterProvider` from `react-router` and ignore this prop
  1796. */
  1797. flushSync?: (fn: () => unknown) => undefined;
  1798. /**
  1799. * An error handler function that will be called for any loader/action/render
  1800. * errors that are encountered in your application. This is useful for
  1801. * logging or reporting errors instead of the `ErrorBoundary` because it's not
  1802. * subject to re-rendering and will only run one time per error.
  1803. *
  1804. * The `errorInfo` parameter is passed along from
  1805. * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
  1806. * and is only present for render errors.
  1807. *
  1808. * ```tsx
  1809. * <RouterProvider unstable_onError=(error, errorInfo) => {
  1810. * console.error(error, errorInfo);
  1811. * reportToErrorService(error, errorInfo);
  1812. * }} />
  1813. * ```
  1814. */
  1815. unstable_onError?: unstable_ClientOnErrorFunction;
  1816. /**
  1817. * Control whether router state updates are internally wrapped in
  1818. * [`React.startTransition`](https://react.dev/reference/react/startTransition).
  1819. *
  1820. * - When left `undefined`, all state updates are wrapped in
  1821. * `React.startTransition`
  1822. * - This can lead to buggy behaviors if you are wrapping your own
  1823. * navigations/fetchers in `startTransition`.
  1824. * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
  1825. * in `React.startTransition` and router state changes will be wrapped in
  1826. * `React.startTransition` and also sent through
  1827. * [`useOptimistic`](https://react.dev/reference/react/useOptimistic) to
  1828. * surface mid-navigation router state changes to the UI.
  1829. * - When set to `false`, the router will not leverage `React.startTransition` or
  1830. * `React.useOptimistic` on any navigations or state changes.
  1831. *
  1832. * For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
  1833. */
  1834. unstable_useTransitions?: boolean;
  1835. }
  1836. /**
  1837. * Render the UI for the given {@link DataRouter}. This component should
  1838. * typically be at the top of an app's element tree.
  1839. *
  1840. * ```tsx
  1841. * import { createBrowserRouter } from "react-router";
  1842. * import { RouterProvider } from "react-router/dom";
  1843. * import { createRoot } from "react-dom/client";
  1844. *
  1845. * const router = createBrowserRouter(routes);
  1846. * createRoot(document.getElementById("root")).render(
  1847. * <RouterProvider router={router} />
  1848. * );
  1849. * ```
  1850. *
  1851. * <docs-info>Please note that this component is exported both from
  1852. * `react-router` and `react-router/dom` with the only difference being that the
  1853. * latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
  1854. * implementation. You _almost always_ want to use the version from
  1855. * `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
  1856. *
  1857. *
  1858. * @public
  1859. * @category Data Routers
  1860. * @mode data
  1861. * @param props Props
  1862. * @param {RouterProviderProps.flushSync} props.flushSync n/a
  1863. * @param {RouterProviderProps.unstable_onError} props.unstable_onError n/a
  1864. * @param {RouterProviderProps.router} props.router n/a
  1865. * @param {RouterProviderProps.unstable_useTransitions} props.unstable_useTransitions n/a
  1866. * @returns React element for the rendered router
  1867. */
  1868. declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, unstable_onError, unstable_useTransitions, }: RouterProviderProps): React.ReactElement;
  1869. /**
  1870. * @category Types
  1871. */
  1872. interface MemoryRouterProps {
  1873. /**
  1874. * Application basename
  1875. */
  1876. basename?: string;
  1877. /**
  1878. * Nested {@link Route} elements describing the route tree
  1879. */
  1880. children?: React.ReactNode;
  1881. /**
  1882. * Initial entries in the in-memory history stack
  1883. */
  1884. initialEntries?: InitialEntry[];
  1885. /**
  1886. * Index of `initialEntries` the application should initialize to
  1887. */
  1888. initialIndex?: number;
  1889. /**
  1890. * Control whether router state updates are internally wrapped in
  1891. * [`React.startTransition`](https://react.dev/reference/react/startTransition).
  1892. *
  1893. * - When left `undefined`, all router state updates are wrapped in
  1894. * `React.startTransition`
  1895. * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
  1896. * in `React.startTransition` and all router state updates are wrapped in
  1897. * `React.startTransition`
  1898. * - When set to `false`, the router will not leverage `React.startTransition`
  1899. * on any navigations or state changes.
  1900. *
  1901. * For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
  1902. */
  1903. unstable_useTransitions?: boolean;
  1904. }
  1905. /**
  1906. * A declarative {@link Router | `<Router>`} that stores all entries in memory.
  1907. *
  1908. * @public
  1909. * @category Declarative Routers
  1910. * @mode declarative
  1911. * @param props Props
  1912. * @param {MemoryRouterProps.basename} props.basename n/a
  1913. * @param {MemoryRouterProps.children} props.children n/a
  1914. * @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
  1915. * @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
  1916. * @param {MemoryRouterProps.unstable_useTransitions} props.unstable_useTransitions n/a
  1917. * @returns A declarative in-memory {@link Router | `<Router>`} for client-side
  1918. * routing.
  1919. */
  1920. declare function MemoryRouter({ basename, children, initialEntries, initialIndex, unstable_useTransitions, }: MemoryRouterProps): React.ReactElement;
  1921. /**
  1922. * @category Types
  1923. */
  1924. interface NavigateProps {
  1925. /**
  1926. * The path to navigate to. This can be a string or a {@link Path} object
  1927. */
  1928. to: To;
  1929. /**
  1930. * Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
  1931. * stack
  1932. */
  1933. replace?: boolean;
  1934. /**
  1935. * State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
  1936. */
  1937. state?: any;
  1938. /**
  1939. * How to interpret relative routing in the `to` prop.
  1940. * See {@link RelativeRoutingType}.
  1941. */
  1942. relative?: RelativeRoutingType;
  1943. }
  1944. /**
  1945. * A component-based version of {@link useNavigate} to use in a
  1946. * [`React.Component` class](https://react.dev/reference/react/Component) where
  1947. * hooks cannot be used.
  1948. *
  1949. * It's recommended to avoid using this component in favor of {@link useNavigate}.
  1950. *
  1951. * @example
  1952. * <Navigate to="/tasks" />
  1953. *
  1954. * @public
  1955. * @category Components
  1956. * @param props Props
  1957. * @param {NavigateProps.relative} props.relative n/a
  1958. * @param {NavigateProps.replace} props.replace n/a
  1959. * @param {NavigateProps.state} props.state n/a
  1960. * @param {NavigateProps.to} props.to n/a
  1961. * @returns {void}
  1962. *
  1963. */
  1964. declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
  1965. /**
  1966. * @category Types
  1967. */
  1968. interface OutletProps {
  1969. /**
  1970. * Provides a context value to the element tree below the outlet. Use when
  1971. * the parent route needs to provide values to child routes.
  1972. *
  1973. * ```tsx
  1974. * <Outlet context={myContextValue} />
  1975. * ```
  1976. *
  1977. * Access the context with {@link useOutletContext}.
  1978. */
  1979. context?: unknown;
  1980. }
  1981. /**
  1982. * Renders the matching child route of a parent route or nothing if no child
  1983. * route matches.
  1984. *
  1985. * @example
  1986. * import { Outlet } from "react-router";
  1987. *
  1988. * export default function SomeParent() {
  1989. * return (
  1990. * <div>
  1991. * <h1>Parent Content</h1>
  1992. * <Outlet />
  1993. * </div>
  1994. * );
  1995. * }
  1996. *
  1997. * @public
  1998. * @category Components
  1999. * @param props Props
  2000. * @param {OutletProps.context} props.context n/a
  2001. * @returns React element for the rendered outlet or `null` if no child route matches.
  2002. */
  2003. declare function Outlet(props: OutletProps): React.ReactElement | null;
  2004. /**
  2005. * @category Types
  2006. */
  2007. interface PathRouteProps {
  2008. /**
  2009. * Whether the path should be case-sensitive. Defaults to `false`.
  2010. */
  2011. caseSensitive?: NonIndexRouteObject["caseSensitive"];
  2012. /**
  2013. * The path pattern to match. If unspecified or empty, then this becomes a
  2014. * layout route.
  2015. */
  2016. path?: NonIndexRouteObject["path"];
  2017. /**
  2018. * The unique identifier for this route (for use with {@link DataRouter}s)
  2019. */
  2020. id?: NonIndexRouteObject["id"];
  2021. /**
  2022. * A function that returns a promise that resolves to the route object.
  2023. * Used for code-splitting routes.
  2024. * See [`lazy`](../../start/data/route-object#lazy).
  2025. */
  2026. lazy?: LazyRouteFunction<NonIndexRouteObject>;
  2027. /**
  2028. * The route middleware.
  2029. * See [`middleware`](../../start/data/route-object#middleware).
  2030. */
  2031. middleware?: NonIndexRouteObject["middleware"];
  2032. /**
  2033. * The route loader.
  2034. * See [`loader`](../../start/data/route-object#loader).
  2035. */
  2036. loader?: NonIndexRouteObject["loader"];
  2037. /**
  2038. * The route action.
  2039. * See [`action`](../../start/data/route-object#action).
  2040. */
  2041. action?: NonIndexRouteObject["action"];
  2042. hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
  2043. /**
  2044. * The route shouldRevalidate function.
  2045. * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
  2046. */
  2047. shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
  2048. /**
  2049. * The route handle.
  2050. */
  2051. handle?: NonIndexRouteObject["handle"];
  2052. /**
  2053. * Whether this is an index route.
  2054. */
  2055. index?: false;
  2056. /**
  2057. * Child Route components
  2058. */
  2059. children?: React.ReactNode;
  2060. /**
  2061. * The React element to render when this Route matches.
  2062. * Mutually exclusive with `Component`.
  2063. */
  2064. element?: React.ReactNode | null;
  2065. /**
  2066. * The React element to render while this router is loading data.
  2067. * Mutually exclusive with `HydrateFallback`.
  2068. */
  2069. hydrateFallbackElement?: React.ReactNode | null;
  2070. /**
  2071. * The React element to render at this route if an error occurs.
  2072. * Mutually exclusive with `ErrorBoundary`.
  2073. */
  2074. errorElement?: React.ReactNode | null;
  2075. /**
  2076. * The React Component to render when this route matches.
  2077. * Mutually exclusive with `element`.
  2078. */
  2079. Component?: React.ComponentType | null;
  2080. /**
  2081. * The React Component to render while this router is loading data.
  2082. * Mutually exclusive with `hydrateFallbackElement`.
  2083. */
  2084. HydrateFallback?: React.ComponentType | null;
  2085. /**
  2086. * The React Component to render at this route if an error occurs.
  2087. * Mutually exclusive with `errorElement`.
  2088. */
  2089. ErrorBoundary?: React.ComponentType | null;
  2090. }
  2091. /**
  2092. * @category Types
  2093. */
  2094. interface LayoutRouteProps extends PathRouteProps {
  2095. }
  2096. /**
  2097. * @category Types
  2098. */
  2099. interface IndexRouteProps {
  2100. /**
  2101. * Whether the path should be case-sensitive. Defaults to `false`.
  2102. */
  2103. caseSensitive?: IndexRouteObject["caseSensitive"];
  2104. /**
  2105. * The path pattern to match. If unspecified or empty, then this becomes a
  2106. * layout route.
  2107. */
  2108. path?: IndexRouteObject["path"];
  2109. /**
  2110. * The unique identifier for this route (for use with {@link DataRouter}s)
  2111. */
  2112. id?: IndexRouteObject["id"];
  2113. /**
  2114. * A function that returns a promise that resolves to the route object.
  2115. * Used for code-splitting routes.
  2116. * See [`lazy`](../../start/data/route-object#lazy).
  2117. */
  2118. lazy?: LazyRouteFunction<IndexRouteObject>;
  2119. /**
  2120. * The route middleware.
  2121. * See [`middleware`](../../start/data/route-object#middleware).
  2122. */
  2123. middleware?: IndexRouteObject["middleware"];
  2124. /**
  2125. * The route loader.
  2126. * See [`loader`](../../start/data/route-object#loader).
  2127. */
  2128. loader?: IndexRouteObject["loader"];
  2129. /**
  2130. * The route action.
  2131. * See [`action`](../../start/data/route-object#action).
  2132. */
  2133. action?: IndexRouteObject["action"];
  2134. hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
  2135. /**
  2136. * The route shouldRevalidate function.
  2137. * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
  2138. */
  2139. shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
  2140. /**
  2141. * The route handle.
  2142. */
  2143. handle?: IndexRouteObject["handle"];
  2144. /**
  2145. * Whether this is an index route.
  2146. */
  2147. index: true;
  2148. /**
  2149. * Child Route components
  2150. */
  2151. children?: undefined;
  2152. /**
  2153. * The React element to render when this Route matches.
  2154. * Mutually exclusive with `Component`.
  2155. */
  2156. element?: React.ReactNode | null;
  2157. /**
  2158. * The React element to render while this router is loading data.
  2159. * Mutually exclusive with `HydrateFallback`.
  2160. */
  2161. hydrateFallbackElement?: React.ReactNode | null;
  2162. /**
  2163. * The React element to render at this route if an error occurs.
  2164. * Mutually exclusive with `ErrorBoundary`.
  2165. */
  2166. errorElement?: React.ReactNode | null;
  2167. /**
  2168. * The React Component to render when this route matches.
  2169. * Mutually exclusive with `element`.
  2170. */
  2171. Component?: React.ComponentType | null;
  2172. /**
  2173. * The React Component to render while this router is loading data.
  2174. * Mutually exclusive with `hydrateFallbackElement`.
  2175. */
  2176. HydrateFallback?: React.ComponentType | null;
  2177. /**
  2178. * The React Component to render at this route if an error occurs.
  2179. * Mutually exclusive with `errorElement`.
  2180. */
  2181. ErrorBoundary?: React.ComponentType | null;
  2182. }
  2183. type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
  2184. /**
  2185. * Configures an element to render when a pattern matches the current location.
  2186. * It must be rendered within a {@link Routes} element. Note that these routes
  2187. * do not participate in data loading, actions, code splitting, or any other
  2188. * route module features.
  2189. *
  2190. * @example
  2191. * // Usually used in a declarative router
  2192. * function App() {
  2193. * return (
  2194. * <BrowserRouter>
  2195. * <Routes>
  2196. * <Route index element={<StepOne />} />
  2197. * <Route path="step-2" element={<StepTwo />} />
  2198. * <Route path="step-3" element={<StepThree />} />
  2199. * </Routes>
  2200. * </BrowserRouter>
  2201. * );
  2202. * }
  2203. *
  2204. * // But can be used with a data router as well if you prefer the JSX notation
  2205. * const routes = createRoutesFromElements(
  2206. * <>
  2207. * <Route index loader={step1Loader} Component={StepOne} />
  2208. * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
  2209. * <Route path="step-3" loader={step3Loader} Component={StepThree} />
  2210. * </>
  2211. * );
  2212. *
  2213. * const router = createBrowserRouter(routes);
  2214. *
  2215. * function App() {
  2216. * return <RouterProvider router={router} />;
  2217. * }
  2218. *
  2219. * @public
  2220. * @category Components
  2221. * @param props Props
  2222. * @param {PathRouteProps.action} props.action n/a
  2223. * @param {PathRouteProps.caseSensitive} props.caseSensitive n/a
  2224. * @param {PathRouteProps.Component} props.Component n/a
  2225. * @param {PathRouteProps.children} props.children n/a
  2226. * @param {PathRouteProps.element} props.element n/a
  2227. * @param {PathRouteProps.ErrorBoundary} props.ErrorBoundary n/a
  2228. * @param {PathRouteProps.errorElement} props.errorElement n/a
  2229. * @param {PathRouteProps.handle} props.handle n/a
  2230. * @param {PathRouteProps.HydrateFallback} props.HydrateFallback n/a
  2231. * @param {PathRouteProps.hydrateFallbackElement} props.hydrateFallbackElement n/a
  2232. * @param {PathRouteProps.id} props.id n/a
  2233. * @param {PathRouteProps.index} props.index n/a
  2234. * @param {PathRouteProps.lazy} props.lazy n/a
  2235. * @param {PathRouteProps.loader} props.loader n/a
  2236. * @param {PathRouteProps.path} props.path n/a
  2237. * @param {PathRouteProps.shouldRevalidate} props.shouldRevalidate n/a
  2238. * @returns {void}
  2239. */
  2240. declare function Route(props: RouteProps): React.ReactElement | null;
  2241. /**
  2242. * @category Types
  2243. */
  2244. interface RouterProps {
  2245. /**
  2246. * The base path for the application. This is prepended to all locations
  2247. */
  2248. basename?: string;
  2249. /**
  2250. * Nested {@link Route} elements describing the route tree
  2251. */
  2252. children?: React.ReactNode;
  2253. /**
  2254. * The location to match against. Defaults to the current location.
  2255. * This can be a string or a {@link Location} object.
  2256. */
  2257. location: Partial<Location> | string;
  2258. /**
  2259. * The type of navigation that triggered this `location` change.
  2260. * Defaults to {@link NavigationType.Pop}.
  2261. */
  2262. navigationType?: Action;
  2263. /**
  2264. * The navigator to use for navigation. This is usually a history object
  2265. * or a custom navigator that implements the {@link Navigator} interface.
  2266. */
  2267. navigator: Navigator;
  2268. /**
  2269. * Whether this router is static or not (used for SSR). If `true`, the router
  2270. * will not be reactive to location changes.
  2271. */
  2272. static?: boolean;
  2273. /**
  2274. * Whether this router should wrap navigations in `React.startTransition()`
  2275. */
  2276. unstable_useTransitions: boolean;
  2277. }
  2278. /**
  2279. * Provides location context for the rest of the app.
  2280. *
  2281. * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
  2282. * router that is more specific to your environment such as a {@link BrowserRouter}
  2283. * in web browsers or a {@link ServerRouter} for server rendering.
  2284. *
  2285. * @public
  2286. * @category Declarative Routers
  2287. * @mode declarative
  2288. * @param props Props
  2289. * @param {RouterProps.basename} props.basename n/a
  2290. * @param {RouterProps.children} props.children n/a
  2291. * @param {RouterProps.location} props.location n/a
  2292. * @param {RouterProps.navigationType} props.navigationType n/a
  2293. * @param {RouterProps.navigator} props.navigator n/a
  2294. * @param {RouterProps.static} props.static n/a
  2295. * @param {RouterProps.unstable_useTransitions} props.unstable_useTransitions n/a
  2296. * @returns React element for the rendered router or `null` if the location does
  2297. * not match the {@link props.basename}
  2298. */
  2299. declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, unstable_useTransitions, }: RouterProps): React.ReactElement | null;
  2300. /**
  2301. * @category Types
  2302. */
  2303. interface RoutesProps {
  2304. /**
  2305. * Nested {@link Route} elements
  2306. */
  2307. children?: React.ReactNode;
  2308. /**
  2309. * The {@link Location} to match against. Defaults to the current location.
  2310. */
  2311. location?: Partial<Location> | string;
  2312. }
  2313. /**
  2314. * Renders a branch of {@link Route | `<Route>`s} that best matches the current
  2315. * location. Note that these routes do not participate in [data loading](../../start/framework/route-module#loader),
  2316. * [`action`](../../start/framework/route-module#action), code splitting, or
  2317. * any other [route module](../../start/framework/route-module) features.
  2318. *
  2319. * @example
  2320. * import { Route, Routes } from "react-router";
  2321. *
  2322. * <Routes>
  2323. * <Route index element={<StepOne />} />
  2324. * <Route path="step-2" element={<StepTwo />} />
  2325. * <Route path="step-3" element={<StepThree />} />
  2326. * </Routes>
  2327. *
  2328. * @public
  2329. * @category Components
  2330. * @param props Props
  2331. * @param {RoutesProps.children} props.children n/a
  2332. * @param {RoutesProps.location} props.location n/a
  2333. * @returns React element for the rendered routes or `null` if no route matches
  2334. */
  2335. declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
  2336. interface AwaitResolveRenderFunction<Resolve = any> {
  2337. (data: Awaited<Resolve>): React.ReactNode;
  2338. }
  2339. /**
  2340. * @category Types
  2341. */
  2342. interface AwaitProps<Resolve> {
  2343. /**
  2344. * When using a function, the resolved value is provided as the parameter.
  2345. *
  2346. * ```tsx [2]
  2347. * <Await resolve={reviewsPromise}>
  2348. * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
  2349. * </Await>
  2350. * ```
  2351. *
  2352. * When using React elements, {@link useAsyncValue} will provide the
  2353. * resolved value:
  2354. *
  2355. * ```tsx [2]
  2356. * <Await resolve={reviewsPromise}>
  2357. * <Reviews />
  2358. * </Await>
  2359. *
  2360. * function Reviews() {
  2361. * const resolvedReviews = useAsyncValue();
  2362. * return <div>...</div>;
  2363. * }
  2364. * ```
  2365. */
  2366. children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
  2367. /**
  2368. * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
  2369. * rejects.
  2370. *
  2371. * ```tsx
  2372. * <Await
  2373. * errorElement={<div>Oops</div>}
  2374. * resolve={reviewsPromise}
  2375. * >
  2376. * <Reviews />
  2377. * </Await>
  2378. * ```
  2379. *
  2380. * To provide a more contextual error, you can use the {@link useAsyncError} in a
  2381. * child component
  2382. *
  2383. * ```tsx
  2384. * <Await
  2385. * errorElement={<ReviewsError />}
  2386. * resolve={reviewsPromise}
  2387. * >
  2388. * <Reviews />
  2389. * </Await>
  2390. *
  2391. * function ReviewsError() {
  2392. * const error = useAsyncError();
  2393. * return <div>Error loading reviews: {error.message}</div>;
  2394. * }
  2395. * ```
  2396. *
  2397. * If you do not provide an `errorElement`, the rejected value will bubble up
  2398. * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
  2399. * and be accessible via the {@link useRouteError} hook.
  2400. */
  2401. errorElement?: React.ReactNode;
  2402. /**
  2403. * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
  2404. * returned from a [`loader`](../../start/framework/route-module#loader) to be
  2405. * resolved and rendered.
  2406. *
  2407. * ```tsx
  2408. * import { Await, useLoaderData } from "react-router";
  2409. *
  2410. * export async function loader() {
  2411. * let reviews = getReviews(); // not awaited
  2412. * let book = await getBook();
  2413. * return {
  2414. * book,
  2415. * reviews, // this is a promise
  2416. * };
  2417. * }
  2418. *
  2419. * export default function Book() {
  2420. * const {
  2421. * book,
  2422. * reviews, // this is the same promise
  2423. * } = useLoaderData();
  2424. *
  2425. * return (
  2426. * <div>
  2427. * <h1>{book.title}</h1>
  2428. * <p>{book.description}</p>
  2429. * <React.Suspense fallback={<ReviewsSkeleton />}>
  2430. * <Await
  2431. * // and is the promise we pass to Await
  2432. * resolve={reviews}
  2433. * >
  2434. * <Reviews />
  2435. * </Await>
  2436. * </React.Suspense>
  2437. * </div>
  2438. * );
  2439. * }
  2440. * ```
  2441. */
  2442. resolve: Resolve;
  2443. }
  2444. /**
  2445. * Used to render promise values with automatic error handling.
  2446. *
  2447. * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
  2448. *
  2449. * @example
  2450. * import { Await, useLoaderData } from "react-router";
  2451. *
  2452. * export async function loader() {
  2453. * // not awaited
  2454. * const reviews = getReviews();
  2455. * // awaited (blocks the transition)
  2456. * const book = await fetch("/api/book").then((res) => res.json());
  2457. * return { book, reviews };
  2458. * }
  2459. *
  2460. * function Book() {
  2461. * const { book, reviews } = useLoaderData();
  2462. * return (
  2463. * <div>
  2464. * <h1>{book.title}</h1>
  2465. * <p>{book.description}</p>
  2466. * <React.Suspense fallback={<ReviewsSkeleton />}>
  2467. * <Await
  2468. * resolve={reviews}
  2469. * errorElement={
  2470. * <div>Could not load reviews 😬</div>
  2471. * }
  2472. * children={(resolvedReviews) => (
  2473. * <Reviews items={resolvedReviews} />
  2474. * )}
  2475. * />
  2476. * </React.Suspense>
  2477. * </div>
  2478. * );
  2479. * }
  2480. *
  2481. * @public
  2482. * @category Components
  2483. * @mode framework
  2484. * @mode data
  2485. * @param props Props
  2486. * @param {AwaitProps.children} props.children n/a
  2487. * @param {AwaitProps.errorElement} props.errorElement n/a
  2488. * @param {AwaitProps.resolve} props.resolve n/a
  2489. * @returns React element for the rendered awaited value
  2490. */
  2491. declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
  2492. /**
  2493. * Creates a route config from a React "children" object, which is usually
  2494. * either a `<Route>` element or an array of them. Used internally by
  2495. * `<Routes>` to create a route config from its children.
  2496. *
  2497. * @category Utils
  2498. * @mode data
  2499. * @param children The React children to convert into a route config
  2500. * @param parentPath The path of the parent route, used to generate unique IDs.
  2501. * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
  2502. */
  2503. declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
  2504. /**
  2505. * Create route objects from JSX elements instead of arrays of objects.
  2506. *
  2507. * @example
  2508. * const routes = createRoutesFromElements(
  2509. * <>
  2510. * <Route index loader={step1Loader} Component={StepOne} />
  2511. * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
  2512. * <Route path="step-3" loader={step3Loader} Component={StepThree} />
  2513. * </>
  2514. * );
  2515. *
  2516. * const router = createBrowserRouter(routes);
  2517. *
  2518. * function App() {
  2519. * return <RouterProvider router={router} />;
  2520. * }
  2521. *
  2522. * @name createRoutesFromElements
  2523. * @public
  2524. * @category Utils
  2525. * @mode data
  2526. * @param children The React children to convert into a route config
  2527. * @param parentPath The path of the parent route, used to generate unique IDs.
  2528. * This is used for internal recursion and is not intended to be used by the
  2529. * application developer.
  2530. * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
  2531. */
  2532. declare const createRoutesFromElements: typeof createRoutesFromChildren;
  2533. /**
  2534. * Renders the result of {@link matchRoutes} into a React element.
  2535. *
  2536. * @public
  2537. * @category Utils
  2538. * @param matches The array of {@link RouteMatch | route matches} to render
  2539. * @returns A React element that renders the matched routes or `null` if no matches
  2540. */
  2541. declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
  2542. declare function useRouteComponentProps(): {
  2543. params: Readonly<Params<string>>;
  2544. loaderData: any;
  2545. actionData: any;
  2546. matches: UIMatch<unknown, unknown>[];
  2547. };
  2548. type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
  2549. type RouteComponentType = React.ComponentType<RouteComponentProps>;
  2550. declare function WithComponentProps({ children, }: {
  2551. children: React.ReactElement;
  2552. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  2553. declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
  2554. params: Readonly<Params<string>>;
  2555. loaderData: any;
  2556. actionData: any;
  2557. matches: UIMatch<unknown, unknown>[];
  2558. }, string | React.JSXElementConstructor<any>>;
  2559. declare function useHydrateFallbackProps(): {
  2560. params: Readonly<Params<string>>;
  2561. loaderData: any;
  2562. actionData: any;
  2563. };
  2564. type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
  2565. type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
  2566. declare function WithHydrateFallbackProps({ children, }: {
  2567. children: React.ReactElement;
  2568. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  2569. declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
  2570. params: Readonly<Params<string>>;
  2571. loaderData: any;
  2572. actionData: any;
  2573. }, string | React.JSXElementConstructor<any>>;
  2574. declare function useErrorBoundaryProps(): {
  2575. params: Readonly<Params<string>>;
  2576. loaderData: any;
  2577. actionData: any;
  2578. error: unknown;
  2579. };
  2580. type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
  2581. type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
  2582. declare function WithErrorBoundaryProps({ children, }: {
  2583. children: React.ReactElement;
  2584. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  2585. declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
  2586. params: Readonly<Params<string>>;
  2587. loaderData: any;
  2588. actionData: any;
  2589. error: unknown;
  2590. }, string | React.JSXElementConstructor<any>>;
  2591. interface IndexRouteObject {
  2592. caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
  2593. path?: AgnosticIndexRouteObject["path"];
  2594. id?: AgnosticIndexRouteObject["id"];
  2595. middleware?: AgnosticIndexRouteObject["middleware"];
  2596. loader?: AgnosticIndexRouteObject["loader"];
  2597. action?: AgnosticIndexRouteObject["action"];
  2598. hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
  2599. shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
  2600. handle?: AgnosticIndexRouteObject["handle"];
  2601. index: true;
  2602. children?: undefined;
  2603. element?: React.ReactNode | null;
  2604. hydrateFallbackElement?: React.ReactNode | null;
  2605. errorElement?: React.ReactNode | null;
  2606. Component?: React.ComponentType | null;
  2607. HydrateFallback?: React.ComponentType | null;
  2608. ErrorBoundary?: React.ComponentType | null;
  2609. lazy?: LazyRouteDefinition<RouteObject>;
  2610. }
  2611. interface NonIndexRouteObject {
  2612. caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
  2613. path?: AgnosticNonIndexRouteObject["path"];
  2614. id?: AgnosticNonIndexRouteObject["id"];
  2615. middleware?: AgnosticNonIndexRouteObject["middleware"];
  2616. loader?: AgnosticNonIndexRouteObject["loader"];
  2617. action?: AgnosticNonIndexRouteObject["action"];
  2618. hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
  2619. shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
  2620. handle?: AgnosticNonIndexRouteObject["handle"];
  2621. index?: false;
  2622. children?: RouteObject[];
  2623. element?: React.ReactNode | null;
  2624. hydrateFallbackElement?: React.ReactNode | null;
  2625. errorElement?: React.ReactNode | null;
  2626. Component?: React.ComponentType | null;
  2627. HydrateFallback?: React.ComponentType | null;
  2628. ErrorBoundary?: React.ComponentType | null;
  2629. lazy?: LazyRouteDefinition<RouteObject>;
  2630. }
  2631. type RouteObject = IndexRouteObject | NonIndexRouteObject;
  2632. type DataRouteObject = RouteObject & {
  2633. children?: DataRouteObject[];
  2634. id: string;
  2635. };
  2636. interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
  2637. }
  2638. interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
  2639. }
  2640. type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
  2641. type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
  2642. interface DataRouterContextObject extends Omit<NavigationContextObject, "future" | "unstable_useTransitions"> {
  2643. router: Router$1;
  2644. staticContext?: StaticHandlerContext;
  2645. unstable_onError?: unstable_ClientOnErrorFunction;
  2646. }
  2647. declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
  2648. declare const DataRouterStateContext: React.Context<RouterState | null>;
  2649. type ViewTransitionContextObject = {
  2650. isTransitioning: false;
  2651. } | {
  2652. isTransitioning: true;
  2653. flushSync: boolean;
  2654. currentLocation: Location;
  2655. nextLocation: Location;
  2656. };
  2657. declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
  2658. type FetchersContextObject = Map<string, any>;
  2659. declare const FetchersContext: React.Context<FetchersContextObject>;
  2660. declare const AwaitContext: React.Context<TrackedPromise | null>;
  2661. declare const AwaitContextProvider: (props: React.ComponentProps<typeof AwaitContext.Provider>) => React.FunctionComponentElement<React.ProviderProps<TrackedPromise | null>>;
  2662. interface NavigateOptions {
  2663. /** Replace the current entry in the history stack instead of pushing a new one */
  2664. replace?: boolean;
  2665. /** Adds persistent client side routing state to the next location */
  2666. state?: any;
  2667. /** If you are using {@link https://api.reactrouter.com/v7/functions/react_router.ScrollRestoration.html <ScrollRestoration>}, prevent the scroll position from being reset to the top of the window when navigating */
  2668. preventScrollReset?: boolean;
  2669. /** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
  2670. relative?: RelativeRoutingType;
  2671. /** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
  2672. flushSync?: boolean;
  2673. /** Enables a {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API View Transition} for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the {@link https://api.reactrouter.com/v7/functions/react_router.useViewTransitionState.html useViewTransitionState()} hook. */
  2674. viewTransition?: boolean;
  2675. }
  2676. /**
  2677. * A Navigator is a "location changer"; it's how you get to different locations.
  2678. *
  2679. * Every history instance conforms to the Navigator interface, but the
  2680. * distinction is useful primarily when it comes to the low-level `<Router>` API
  2681. * where both the location and a navigator must be provided separately in order
  2682. * to avoid "tearing" that may occur in a suspense-enabled app if the action
  2683. * and/or location were to be read directly from the history instance.
  2684. */
  2685. interface Navigator {
  2686. createHref: History["createHref"];
  2687. encodeLocation?: History["encodeLocation"];
  2688. go: History["go"];
  2689. push(to: To, state?: any, opts?: NavigateOptions): void;
  2690. replace(to: To, state?: any, opts?: NavigateOptions): void;
  2691. }
  2692. interface NavigationContextObject {
  2693. basename: string;
  2694. navigator: Navigator;
  2695. static: boolean;
  2696. unstable_useTransitions: boolean;
  2697. future: {};
  2698. }
  2699. declare const NavigationContext: React.Context<NavigationContextObject>;
  2700. interface LocationContextObject {
  2701. location: Location;
  2702. navigationType: Action;
  2703. }
  2704. declare const LocationContext: React.Context<LocationContextObject>;
  2705. interface RouteContextObject {
  2706. outlet: React.ReactElement | null;
  2707. matches: RouteMatch[];
  2708. isDataRoute: boolean;
  2709. }
  2710. declare const RouteContext: React.Context<RouteContextObject>;
  2711. type Primitive = null | undefined | string | number | boolean | symbol | bigint;
  2712. type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
  2713. interface HtmlLinkProps {
  2714. /**
  2715. * Address of the hyperlink
  2716. */
  2717. href?: string;
  2718. /**
  2719. * How the element handles crossorigin requests
  2720. */
  2721. crossOrigin?: "anonymous" | "use-credentials";
  2722. /**
  2723. * Relationship between the document containing the hyperlink and the destination resource
  2724. */
  2725. rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
  2726. /**
  2727. * Applicable media: "screen", "print", "(max-width: 764px)"
  2728. */
  2729. media?: string;
  2730. /**
  2731. * Integrity metadata used in Subresource Integrity checks
  2732. */
  2733. integrity?: string;
  2734. /**
  2735. * Language of the linked resource
  2736. */
  2737. hrefLang?: string;
  2738. /**
  2739. * Hint for the type of the referenced resource
  2740. */
  2741. type?: string;
  2742. /**
  2743. * Referrer policy for fetches initiated by the element
  2744. */
  2745. referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
  2746. /**
  2747. * Sizes of the icons (for rel="icon")
  2748. */
  2749. sizes?: string;
  2750. /**
  2751. * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
  2752. */
  2753. as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
  2754. /**
  2755. * Color to use when customizing a site's icon (for rel="mask-icon")
  2756. */
  2757. color?: string;
  2758. /**
  2759. * Whether the link is disabled
  2760. */
  2761. disabled?: boolean;
  2762. /**
  2763. * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
  2764. */
  2765. title?: string;
  2766. /**
  2767. * Images to use in different situations, e.g., high-resolution displays,
  2768. * small monitors, etc. (for rel="preload")
  2769. */
  2770. imageSrcSet?: string;
  2771. /**
  2772. * Image sizes for different page layouts (for rel="preload")
  2773. */
  2774. imageSizes?: string;
  2775. }
  2776. interface HtmlLinkPreloadImage extends HtmlLinkProps {
  2777. /**
  2778. * Relationship between the document containing the hyperlink and the destination resource
  2779. */
  2780. rel: "preload";
  2781. /**
  2782. * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
  2783. */
  2784. as: "image";
  2785. /**
  2786. * Address of the hyperlink
  2787. */
  2788. href?: string;
  2789. /**
  2790. * Images to use in different situations, e.g., high-resolution displays,
  2791. * small monitors, etc. (for rel="preload")
  2792. */
  2793. imageSrcSet: string;
  2794. /**
  2795. * Image sizes for different page layouts (for rel="preload")
  2796. */
  2797. imageSizes?: string;
  2798. }
  2799. /**
  2800. * Represents a `<link>` element.
  2801. *
  2802. * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
  2803. */
  2804. type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
  2805. imageSizes?: never;
  2806. });
  2807. interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
  2808. /**
  2809. * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
  2810. * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
  2811. * element
  2812. */
  2813. nonce?: string | undefined;
  2814. /**
  2815. * The absolute path of the page to prefetch, e.g. `/absolute/path`.
  2816. */
  2817. page: string;
  2818. }
  2819. type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
  2820. type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
  2821. [key: PropertyKey]: Serializable;
  2822. } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
  2823. type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
  2824. type IsAny<T> = 0 extends 1 & T ? true : false;
  2825. type Func = (...args: any[]) => unknown;
  2826. type Pretty<T> = {
  2827. [K in keyof T]: T[K];
  2828. } & {};
  2829. type Normalize<T> = _Normalize<UnionKeys<T>, T>;
  2830. type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
  2831. [K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
  2832. } & {
  2833. [K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
  2834. } & {
  2835. [K in Key as K extends keyof U ? never : K]?: undefined;
  2836. }> : never;
  2837. type UnionKeys<T> = T extends any ? keyof T : never;
  2838. type RouteModule$1 = {
  2839. meta?: Func;
  2840. links?: Func;
  2841. headers?: Func;
  2842. loader?: Func;
  2843. clientLoader?: Func;
  2844. action?: Func;
  2845. clientAction?: Func;
  2846. HydrateFallback?: Func;
  2847. default?: Func;
  2848. ErrorBoundary?: Func;
  2849. [key: string]: unknown;
  2850. };
  2851. /**
  2852. * A brand that can be applied to a type to indicate that it will serialize
  2853. * to a specific type when transported to the client from a loader.
  2854. * Only use this if you have additional serialization/deserialization logic
  2855. * in your application.
  2856. */
  2857. type unstable_SerializesTo<T> = {
  2858. unstable__ReactRouter_SerializesTo: [T];
  2859. };
  2860. 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 ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<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> ? {
  2861. [K in keyof T]: Serialize<T[K]>;
  2862. } : undefined;
  2863. type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
  2864. type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
  2865. type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
  2866. type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
  2867. type ServerDataFrom<T> = ServerData<DataFrom<T>>;
  2868. type ClientDataFrom<T> = ClientData<DataFrom<T>>;
  2869. type ClientDataFunctionArgs<Params> = {
  2870. /**
  2871. * 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.
  2872. *
  2873. * @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.
  2874. **/
  2875. request: Request;
  2876. /**
  2877. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
  2878. * @example
  2879. * // app/routes.ts
  2880. * route("teams/:teamId", "./team.tsx"),
  2881. *
  2882. * // app/team.tsx
  2883. * export function clientLoader({
  2884. * params,
  2885. * }: Route.ClientLoaderArgs) {
  2886. * params.teamId;
  2887. * // ^ string
  2888. * }
  2889. **/
  2890. params: Params;
  2891. /**
  2892. * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
  2893. * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
  2894. */
  2895. unstable_pattern: string;
  2896. /**
  2897. * When `future.v8_middleware` is not enabled, this is undefined.
  2898. *
  2899. * When `future.v8_middleware` is enabled, this is an instance of
  2900. * `RouterContextProvider` and can be used to access context values
  2901. * from your route middlewares. You may pass in initial context values in your
  2902. * `<HydratedRouter getContext>` prop
  2903. */
  2904. context: Readonly<RouterContextProvider>;
  2905. };
  2906. type ServerDataFunctionArgs<Params> = {
  2907. /** 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. */
  2908. request: Request;
  2909. /**
  2910. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
  2911. * @example
  2912. * // app/routes.ts
  2913. * route("teams/:teamId", "./team.tsx"),
  2914. *
  2915. * // app/team.tsx
  2916. * export function loader({
  2917. * params,
  2918. * }: Route.LoaderArgs) {
  2919. * params.teamId;
  2920. * // ^ string
  2921. * }
  2922. **/
  2923. params: Params;
  2924. /**
  2925. * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
  2926. * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
  2927. */
  2928. unstable_pattern: string;
  2929. /**
  2930. * Without `future.v8_middleware` enabled, this is the context passed in
  2931. * to your server adapter's `getLoadContext` function. It's a way to bridge the
  2932. * gap between the adapter's request/response API with your React Router app.
  2933. * It is only applicable if you are using a custom server adapter.
  2934. *
  2935. * With `future.v8_middleware` enabled, this is an instance of
  2936. * `RouterContextProvider` and can be used for type-safe access to
  2937. * context value set in your route middlewares. If you are using a custom
  2938. * server adapter, you may provide an initial set of context values from your
  2939. * `getLoadContext` function.
  2940. */
  2941. context: MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : AppLoadContext;
  2942. };
  2943. type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
  2944. ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
  2945. ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
  2946. type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
  2947. type IsHydrate<ClientLoader> = ClientLoader extends {
  2948. hydrate: true;
  2949. } ? true : ClientLoader extends {
  2950. hydrate: false;
  2951. } ? false : false;
  2952. type GetLoaderData<T extends RouteModule$1> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
  2953. HydrateFallback: Func;
  2954. } ? true : false>;
  2955. type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
  2956. HasHydrateFallback,
  2957. ClientLoaderHydrate
  2958. ] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
  2959. IsDefined<ClientLoaderData>,
  2960. IsDefined<ServerLoaderData>
  2961. ] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
  2962. type GetActionData<T extends RouteModule$1> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
  2963. type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
  2964. IsDefined<ServerActionData>,
  2965. IsDefined<ClientActionData>
  2966. ] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
  2967. interface RouteModules {
  2968. [routeId: string]: RouteModule | undefined;
  2969. }
  2970. /**
  2971. * The shape of a route module shipped to the client
  2972. */
  2973. interface RouteModule {
  2974. clientAction?: ClientActionFunction;
  2975. clientLoader?: ClientLoaderFunction;
  2976. clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
  2977. ErrorBoundary?: ErrorBoundaryComponent;
  2978. HydrateFallback?: HydrateFallbackComponent;
  2979. Layout?: LayoutComponent;
  2980. default: RouteComponent;
  2981. handle?: RouteHandle;
  2982. links?: LinksFunction;
  2983. meta?: MetaFunction;
  2984. shouldRevalidate?: ShouldRevalidateFunction;
  2985. }
  2986. /**
  2987. * The shape of a route module on the server
  2988. */
  2989. interface ServerRouteModule extends RouteModule {
  2990. action?: ActionFunction;
  2991. headers?: HeadersFunction | {
  2992. [name: string]: string;
  2993. };
  2994. loader?: LoaderFunction;
  2995. middleware?: MiddlewareFunction<Response>[];
  2996. }
  2997. /**
  2998. * A function that handles data mutations for a route on the client
  2999. */
  3000. type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
  3001. /**
  3002. * Arguments passed to a route `clientAction` function
  3003. */
  3004. type ClientActionFunctionArgs = ActionFunctionArgs & {
  3005. serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
  3006. };
  3007. /**
  3008. * A function that loads data for a route on the client
  3009. */
  3010. type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
  3011. hydrate?: boolean;
  3012. };
  3013. /**
  3014. * Arguments passed to a route `clientLoader` function
  3015. */
  3016. type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
  3017. serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
  3018. };
  3019. /**
  3020. * ErrorBoundary to display for this route
  3021. */
  3022. type ErrorBoundaryComponent = ComponentType;
  3023. type HeadersArgs = {
  3024. loaderHeaders: Headers;
  3025. parentHeaders: Headers;
  3026. actionHeaders: Headers;
  3027. errorHeaders: Headers | undefined;
  3028. };
  3029. /**
  3030. * A function that returns HTTP headers to be used for a route. These headers
  3031. * will be merged with (and take precedence over) headers from parent routes.
  3032. */
  3033. interface HeadersFunction {
  3034. (args: HeadersArgs): Headers | HeadersInit;
  3035. }
  3036. /**
  3037. * `<Route HydrateFallback>` component to render on initial loads
  3038. * when client loaders are present
  3039. */
  3040. type HydrateFallbackComponent = ComponentType;
  3041. /**
  3042. * Optional, root-only `<Route Layout>` component to wrap the root content in.
  3043. * Useful for defining the <html>/<head>/<body> document shell shared by the
  3044. * Component, HydrateFallback, and ErrorBoundary
  3045. */
  3046. type LayoutComponent = ComponentType<{
  3047. children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
  3048. }>;
  3049. /**
  3050. * A function that defines `<link>` tags to be inserted into the `<head>` of
  3051. * the document on route transitions.
  3052. *
  3053. * @see https://reactrouter.com/start/framework/route-module#meta
  3054. */
  3055. interface LinksFunction {
  3056. (): LinkDescriptor[];
  3057. }
  3058. interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
  3059. id: RouteId;
  3060. pathname: DataRouteMatch["pathname"];
  3061. /** @deprecated Use `MetaMatch.loaderData` instead */
  3062. data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
  3063. loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
  3064. handle?: RouteHandle;
  3065. params: DataRouteMatch["params"];
  3066. meta: MetaDescriptor[];
  3067. error?: unknown;
  3068. }
  3069. type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
  3070. [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
  3071. }[keyof MatchLoaders]>;
  3072. interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
  3073. /** @deprecated Use `MetaArgs.loaderData` instead */
  3074. data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
  3075. loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
  3076. params: Params;
  3077. location: Location;
  3078. matches: MetaMatches<MatchLoaders>;
  3079. error?: unknown;
  3080. }
  3081. /**
  3082. * A function that returns an array of data objects to use for rendering
  3083. * metadata HTML tags in a route. These tags are not rendered on descendant
  3084. * routes in the route hierarchy. In other words, they will only be rendered on
  3085. * the route in which they are exported.
  3086. *
  3087. * @param Loader - The type of the current route's loader function
  3088. * @param MatchLoaders - Mapping from a parent route's filepath to its loader
  3089. * function type
  3090. *
  3091. * Note that parent route filepaths are relative to the `app/` directory.
  3092. *
  3093. * For example, if this meta function is for `/sales/customers/$customerId`:
  3094. *
  3095. * ```ts
  3096. * // app/root.tsx
  3097. * const loader = () => ({ hello: "world" })
  3098. * export type Loader = typeof loader
  3099. *
  3100. * // app/routes/sales.tsx
  3101. * const loader = () => ({ salesCount: 1074 })
  3102. * export type Loader = typeof loader
  3103. *
  3104. * // app/routes/sales/customers.tsx
  3105. * const loader = () => ({ customerCount: 74 })
  3106. * export type Loader = typeof loader
  3107. *
  3108. * // app/routes/sales/customers/$customersId.tsx
  3109. * import type { Loader as RootLoader } from "../../../root"
  3110. * import type { Loader as SalesLoader } from "../../sales"
  3111. * import type { Loader as CustomersLoader } from "../../sales/customers"
  3112. *
  3113. * const loader = () => ({ name: "Customer name" })
  3114. *
  3115. * const meta: MetaFunction<typeof loader, {
  3116. * "root": RootLoader,
  3117. * "routes/sales": SalesLoader,
  3118. * "routes/sales/customers": CustomersLoader,
  3119. * }> = ({ data, matches }) => {
  3120. * const { name } = data
  3121. * // ^? string
  3122. * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
  3123. * // ^? number
  3124. * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
  3125. * // ^? number
  3126. * const { hello } = matches.find((match) => match.id === "root").data
  3127. * // ^? "world"
  3128. * }
  3129. * ```
  3130. */
  3131. interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
  3132. (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
  3133. }
  3134. type MetaDescriptor = {
  3135. charSet: "utf-8";
  3136. } | {
  3137. title: string;
  3138. } | {
  3139. name: string;
  3140. content: string;
  3141. } | {
  3142. property: string;
  3143. content: string;
  3144. } | {
  3145. httpEquiv: string;
  3146. content: string;
  3147. } | {
  3148. "script:ld+json": LdJsonObject;
  3149. } | {
  3150. tagName: "meta" | "link";
  3151. [name: string]: string;
  3152. } | {
  3153. [name: string]: unknown;
  3154. };
  3155. type LdJsonObject = {
  3156. [Key in string]: LdJsonValue;
  3157. } & {
  3158. [Key in string]?: LdJsonValue | undefined;
  3159. };
  3160. type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
  3161. type LdJsonPrimitive = string | number | boolean | null;
  3162. type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
  3163. /**
  3164. * A React component that is rendered for a route.
  3165. */
  3166. type RouteComponent = ComponentType<{}>;
  3167. /**
  3168. * An arbitrary object that is associated with a route.
  3169. *
  3170. * @see https://reactrouter.com/how-to/using-handle
  3171. */
  3172. type RouteHandle = unknown;
  3173. type unstable_ServerInstrumentation = {
  3174. handler?: unstable_InstrumentRequestHandlerFunction;
  3175. route?: unstable_InstrumentRouteFunction;
  3176. };
  3177. type unstable_ClientInstrumentation = {
  3178. router?: unstable_InstrumentRouterFunction;
  3179. route?: unstable_InstrumentRouteFunction;
  3180. };
  3181. type unstable_InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
  3182. type unstable_InstrumentRouterFunction = (router: InstrumentableRouter) => void;
  3183. type unstable_InstrumentRouteFunction = (route: InstrumentableRoute) => void;
  3184. type unstable_InstrumentationHandlerResult = {
  3185. status: "success";
  3186. error: undefined;
  3187. } | {
  3188. status: "error";
  3189. error: Error;
  3190. };
  3191. type InstrumentFunction<T> = (handler: () => Promise<unstable_InstrumentationHandlerResult>, info: T) => Promise<void>;
  3192. type ReadonlyRequest = {
  3193. method: string;
  3194. url: string;
  3195. headers: Pick<Headers, "get">;
  3196. };
  3197. type ReadonlyContext = MiddlewareEnabled extends true ? Pick<RouterContextProvider, "get"> : Readonly<AppLoadContext>;
  3198. type InstrumentableRoute = {
  3199. id: string;
  3200. index: boolean | undefined;
  3201. path: string | undefined;
  3202. instrument(instrumentations: RouteInstrumentations): void;
  3203. };
  3204. type RouteInstrumentations = {
  3205. lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  3206. "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  3207. "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  3208. "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  3209. middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  3210. loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  3211. action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  3212. };
  3213. type RouteLazyInstrumentationInfo = undefined;
  3214. type RouteHandlerInstrumentationInfo = Readonly<{
  3215. request: ReadonlyRequest;
  3216. params: LoaderFunctionArgs["params"];
  3217. unstable_pattern: string;
  3218. context: ReadonlyContext;
  3219. }>;
  3220. type InstrumentableRouter = {
  3221. instrument(instrumentations: RouterInstrumentations): void;
  3222. };
  3223. type RouterInstrumentations = {
  3224. navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
  3225. fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
  3226. };
  3227. type RouterNavigationInstrumentationInfo = Readonly<{
  3228. to: string | number;
  3229. currentUrl: string;
  3230. formMethod?: HTMLFormMethod;
  3231. formEncType?: FormEncType;
  3232. formData?: FormData;
  3233. body?: any;
  3234. }>;
  3235. type RouterFetchInstrumentationInfo = Readonly<{
  3236. href: string;
  3237. currentUrl: string;
  3238. fetcherKey: string;
  3239. formMethod?: HTMLFormMethod;
  3240. formEncType?: FormEncType;
  3241. formData?: FormData;
  3242. body?: any;
  3243. }>;
  3244. type InstrumentableRequestHandler = {
  3245. instrument(instrumentations: RequestHandlerInstrumentations): void;
  3246. };
  3247. type RequestHandlerInstrumentations = {
  3248. request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
  3249. };
  3250. type RequestHandlerInstrumentationInfo = Readonly<{
  3251. request: ReadonlyRequest;
  3252. context: ReadonlyContext | undefined;
  3253. }>;
  3254. export { type RouterState as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyResult as D, type PathMatch as E, type Func as F, type GetLoaderData as G, type HeadersFunction as H, type Navigation as I, Action as J, type RouteObject as K, type Location as L, type MetaFunction as M, type Normalize as N, type InitialEntry as O, type Params as P, type HydrationState as Q, type RouteModule$1 as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type IndexRouteObject as V, type RouteComponentType as W, type HydrateFallbackType as X, type ErrorBoundaryType as Y, type NonIndexRouteObject as Z, type Equal as _, type ClientLoaderFunction as a, type RouterProviderProps as a$, type PatchRoutesOnNavigationFunction as a0, type DataRouteObject as a1, type StaticHandler as a2, type GetScrollPositionFunction as a3, type GetScrollRestorationKeyFunction as a4, type StaticHandlerContext as a5, type Fetcher as a6, type NavigationStates as a7, type RouterSubscriber as a8, type RouterNavigateOptions as a9, IDLE_FETCHER as aA, IDLE_BLOCKER as aB, data as aC, generatePath as aD, isRouteErrorResponse as aE, matchPath as aF, matchRoutes as aG, redirect as aH, redirectDocument as aI, replace as aJ, resolvePath as aK, type DataRouteMatch as aL, type Navigator as aM, type PatchRoutesOnNavigationFunctionArgs as aN, type RouteMatch as aO, AwaitContextProvider as aP, type AwaitProps as aQ, type IndexRouteProps as aR, type unstable_ClientOnErrorFunction as aS, type LayoutRouteProps as aT, type MemoryRouterOpts as aU, type MemoryRouterProps as aV, type NavigateProps as aW, type OutletProps as aX, type PathRouteProps as aY, type RouteProps as aZ, type RouterProps as a_, type RouterFetchOptions as aa, type RevalidationState as ab, type ActionFunctionArgs as ac, type DataStrategyFunctionArgs as ad, type DataStrategyMatch as ae, DataWithResponseInit as af, type ErrorResponse as ag, type FormEncType as ah, type FormMethod as ai, type HTMLFormMethod as aj, type LazyRouteFunction as ak, type LoaderFunctionArgs as al, type MiddlewareFunction as am, type PathParam as an, type RedirectFunction as ao, type RouterContext as ap, type ShouldRevalidateFunctionArgs as aq, createContext as ar, createPath as as, parsePath as at, type unstable_ServerInstrumentation as au, type unstable_InstrumentRequestHandlerFunction as av, type unstable_InstrumentRouterFunction as aw, type unstable_InstrumentRouteFunction as ax, type unstable_InstrumentationHandlerResult as ay, IDLE_NAVIGATION as az, type LinksFunction as b, type RoutesProps as b0, Await as b1, MemoryRouter as b2, Navigate as b3, Outlet as b4, Route as b5, Router as b6, RouterProvider as b7, Routes as b8, createMemoryRouter as b9, WithHydrateFallbackProps as bA, withHydrateFallbackProps as bB, WithErrorBoundaryProps as bC, withErrorBoundaryProps as bD, type RouteManifest as bE, type ServerRouteModule as bF, type History as bG, type FutureConfig as bH, type CreateStaticHandlerOptions as bI, createRoutesFromChildren as ba, createRoutesFromElements as bb, renderMatches as bc, type ClientActionFunctionArgs as bd, type ClientLoaderFunctionArgs as be, type HeadersArgs as bf, type MetaArgs as bg, type PageLinkDescriptor as bh, type HtmlLinkDescriptor as bi, type Future as bj, type unstable_SerializesTo as bk, createBrowserHistory as bl, invariant as bm, createRouter as bn, ErrorResponseImpl as bo, DataRouterContext as bp, DataRouterStateContext as bq, FetchersContext as br, LocationContext as bs, NavigationContext as bt, RouteContext as bu, ViewTransitionContext as bv, hydrationRouteProperties as bw, mapRouteProperties as bx, WithComponentProps as by, withComponentProps as bz, RouterContextProvider as c, type LoaderFunction as d, type RouterInit as e, type LinkDescriptor as f, type Pretty as g, type MetaDescriptor as h, type ServerDataFunctionArgs as i, type MiddlewareNextFunction as j, type ClientDataFunctionArgs as k, type ServerDataFrom as l, type GetActionData as m, type Router$1 as n, type RouteModules as o, type DataStrategyFunction as p, type MiddlewareEnabled as q, type AppLoadContext as r, type NavigateOptions as s, type Blocker as t, type unstable_ClientInstrumentation as u, type SerializeFrom as v, type RelativeRoutingType as w, type ParamParseKey as x, type Path as y, type PathPattern as z };