router-CwNp5l9u.d.mts 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273
  1. import * as React from 'react';
  2. import { ComponentType, ReactElement } from 'react';
  3. /**
  4. * Actions represent the type of change to a location value.
  5. */
  6. declare enum Action {
  7. /**
  8. * A POP indicates a change to an arbitrary index in the history stack, such
  9. * as a back or forward navigation. It does not describe the direction of the
  10. * navigation, only that the current index changed.
  11. *
  12. * Note: This is the default action for newly created history objects.
  13. */
  14. Pop = "POP",
  15. /**
  16. * A PUSH indicates a new entry being added to the history stack, such as when
  17. * a link is clicked and a new page loads. When this happens, all subsequent
  18. * entries in the stack are lost.
  19. */
  20. Push = "PUSH",
  21. /**
  22. * A REPLACE indicates the entry at the current index in the history stack
  23. * being replaced by a new one.
  24. */
  25. Replace = "REPLACE"
  26. }
  27. /**
  28. * The pathname, search, and hash values of a URL.
  29. */
  30. interface Path {
  31. /**
  32. * A URL pathname, beginning with a /.
  33. */
  34. pathname: string;
  35. /**
  36. * A URL search string, beginning with a ?.
  37. */
  38. search: string;
  39. /**
  40. * A URL fragment identifier, beginning with a #.
  41. */
  42. hash: string;
  43. }
  44. /**
  45. * An entry in a history stack. A location contains information about the
  46. * URL path, as well as possibly some arbitrary state and a key.
  47. */
  48. interface Location<State = any> extends Path {
  49. /**
  50. * A value of arbitrary data associated with this location.
  51. */
  52. state: State;
  53. /**
  54. * A unique string associated with this location. May be used to safely store
  55. * and retrieve data in some other storage API, like `localStorage`.
  56. *
  57. * Note: This value is always "default" on the initial location.
  58. */
  59. key: string;
  60. }
  61. /**
  62. * A change to the current location.
  63. */
  64. interface Update {
  65. /**
  66. * The action that triggered the change.
  67. */
  68. action: Action;
  69. /**
  70. * The new location.
  71. */
  72. location: Location;
  73. /**
  74. * The delta between this location and the former location in the history stack
  75. */
  76. delta: number | null;
  77. }
  78. /**
  79. * A function that receives notifications about location changes.
  80. */
  81. interface Listener {
  82. (update: Update): void;
  83. }
  84. /**
  85. * Describes a location that is the destination of some navigation used in
  86. * {@link Link}, {@link useNavigate}, etc.
  87. */
  88. type To = string | Partial<Path>;
  89. /**
  90. * A history is an interface to the navigation stack. The history serves as the
  91. * source of truth for the current location, as well as provides a set of
  92. * methods that may be used to change it.
  93. *
  94. * It is similar to the DOM's `window.history` object, but with a smaller, more
  95. * focused API.
  96. */
  97. interface History {
  98. /**
  99. * The last action that modified the current location. This will always be
  100. * Action.Pop when a history instance is first created. This value is mutable.
  101. */
  102. readonly action: Action;
  103. /**
  104. * The current location. This value is mutable.
  105. */
  106. readonly location: Location;
  107. /**
  108. * Returns a valid href for the given `to` value that may be used as
  109. * the value of an <a href> attribute.
  110. *
  111. * @param to - The destination URL
  112. */
  113. createHref(to: To): string;
  114. /**
  115. * Returns a URL for the given `to` value
  116. *
  117. * @param to - The destination URL
  118. */
  119. createURL(to: To): URL;
  120. /**
  121. * Encode a location the same way window.history would do (no-op for memory
  122. * history) so we ensure our PUSH/REPLACE navigations for data routers
  123. * behave the same as POP
  124. *
  125. * @param to Unencoded path
  126. */
  127. encodeLocation(to: To): Path;
  128. /**
  129. * Pushes a new location onto the history stack, increasing its length by one.
  130. * If there were any entries in the stack after the current one, they are
  131. * lost.
  132. *
  133. * @param to - The new URL
  134. * @param state - Data to associate with the new location
  135. */
  136. push(to: To, state?: any): void;
  137. /**
  138. * Replaces the current location in the history stack with a new one. The
  139. * location that was replaced will no longer be available.
  140. *
  141. * @param to - The new URL
  142. * @param state - Data to associate with the new location
  143. */
  144. replace(to: To, state?: any): void;
  145. /**
  146. * Navigates `n` entries backward/forward in the history stack relative to the
  147. * current index. For example, a "back" navigation would use go(-1).
  148. *
  149. * @param delta - The delta in the stack index
  150. */
  151. go(delta: number): void;
  152. /**
  153. * Sets up a listener that will be called whenever the current location
  154. * changes.
  155. *
  156. * @param listener - A function that will be called when the location changes
  157. * @returns unlisten - A function that may be used to stop listening
  158. */
  159. listen(listener: Listener): () => void;
  160. }
  161. /**
  162. * A user-supplied object that describes a location. Used when providing
  163. * entries to `createMemoryHistory` via its `initialEntries` option.
  164. */
  165. type InitialEntry = string | Partial<Location>;
  166. /**
  167. * A browser history stores the current location in regular URLs in a web
  168. * browser environment. This is the standard for most web apps and provides the
  169. * cleanest URLs the browser's address bar.
  170. *
  171. * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
  172. */
  173. interface BrowserHistory extends UrlHistory {
  174. }
  175. type BrowserHistoryOptions = UrlHistoryOptions;
  176. /**
  177. * Browser history stores the location in regular URLs. This is the standard for
  178. * most web apps, but it requires some configuration on the server to ensure you
  179. * serve the same app at multiple URLs.
  180. *
  181. * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
  182. */
  183. declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
  184. /**
  185. * @private
  186. */
  187. declare function invariant(value: boolean, message?: string): asserts value;
  188. declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
  189. /**
  190. * Creates a string URL path from the given pathname, search, and hash components.
  191. *
  192. * @category Utils
  193. */
  194. declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
  195. /**
  196. * Parses a string URL path into its separate pathname, search, and hash components.
  197. *
  198. * @category Utils
  199. */
  200. declare function parsePath(path: string): Partial<Path>;
  201. interface UrlHistory extends History {
  202. }
  203. type UrlHistoryOptions = {
  204. window?: Window;
  205. v5Compat?: boolean;
  206. };
  207. /**
  208. * An augmentable interface users can modify in their app-code to opt into
  209. * future-flag-specific types
  210. */
  211. interface Future {
  212. }
  213. type MiddlewareEnabled = Future extends {
  214. v8_middleware: infer T extends boolean;
  215. } ? T : false;
  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. declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
  1068. hasErrorBoundary: boolean;
  1069. };
  1070. declare const hydrationRouteProperties: (keyof RouteObject)[];
  1071. /**
  1072. * @category Data Routers
  1073. */
  1074. interface MemoryRouterOpts {
  1075. /**
  1076. * Basename path for the application.
  1077. */
  1078. basename?: string;
  1079. /**
  1080. * A function that returns an {@link RouterContextProvider} instance
  1081. * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
  1082. * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
  1083. * This function is called to generate a fresh `context` instance on each
  1084. * navigation or fetcher call.
  1085. */
  1086. getContext?: RouterInit["getContext"];
  1087. /**
  1088. * Future flags to enable for the router.
  1089. */
  1090. future?: Partial<FutureConfig>;
  1091. /**
  1092. * Hydration data to initialize the router with if you have already performed
  1093. * data loading on the server.
  1094. */
  1095. hydrationData?: HydrationState;
  1096. /**
  1097. * Initial entries in the in-memory history stack
  1098. */
  1099. initialEntries?: InitialEntry[];
  1100. /**
  1101. * Index of `initialEntries` the application should initialize to
  1102. */
  1103. initialIndex?: number;
  1104. /**
  1105. * Array of instrumentation objects allowing you to instrument the router and
  1106. * individual routes prior to router initialization (and on any subsequently
  1107. * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
  1108. * mostly useful for observability such as wrapping navigations, fetches,
  1109. * as well as route loaders/actions/middlewares with logging and/or performance
  1110. * tracing. See the [docs](../../how-to/instrumentation) for more information.
  1111. *
  1112. * ```tsx
  1113. * let router = createBrowserRouter(routes, {
  1114. * unstable_instrumentations: [logging]
  1115. * });
  1116. *
  1117. *
  1118. * let logging = {
  1119. * router({ instrument }) {
  1120. * instrument({
  1121. * navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
  1122. * fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
  1123. * });
  1124. * },
  1125. * route({ instrument, id }) {
  1126. * instrument({
  1127. * middleware: (impl, info) => logExecution(
  1128. * `middleware ${info.request.url} (route ${id})`,
  1129. * impl
  1130. * ),
  1131. * loader: (impl, info) => logExecution(
  1132. * `loader ${info.request.url} (route ${id})`,
  1133. * impl
  1134. * ),
  1135. * action: (impl, info) => logExecution(
  1136. * `action ${info.request.url} (route ${id})`,
  1137. * impl
  1138. * ),
  1139. * })
  1140. * }
  1141. * };
  1142. *
  1143. * async function logExecution(label: string, impl: () => Promise<void>) {
  1144. * let start = performance.now();
  1145. * console.log(`start ${label}`);
  1146. * await impl();
  1147. * let duration = Math.round(performance.now() - start);
  1148. * console.log(`end ${label} (${duration}ms)`);
  1149. * }
  1150. * ```
  1151. */
  1152. unstable_instrumentations?: unstable_ClientInstrumentation[];
  1153. /**
  1154. * Override the default data strategy of running loaders in parallel -
  1155. * see the [docs](../../how-to/data-strategy) for more information.
  1156. *
  1157. * ```tsx
  1158. * let router = createBrowserRouter(routes, {
  1159. * async dataStrategy({
  1160. * matches,
  1161. * request,
  1162. * runClientMiddleware,
  1163. * }) {
  1164. * const matchesToLoad = matches.filter((m) =>
  1165. * m.shouldCallHandler(),
  1166. * );
  1167. *
  1168. * const results: Record<string, DataStrategyResult> = {};
  1169. * await runClientMiddleware(() =>
  1170. * Promise.all(
  1171. * matchesToLoad.map(async (match) => {
  1172. * results[match.route.id] = await match.resolve();
  1173. * }),
  1174. * ),
  1175. * );
  1176. * return results;
  1177. * },
  1178. * });
  1179. * ```
  1180. */
  1181. dataStrategy?: DataStrategyFunction;
  1182. /**
  1183. * Lazily define portions of the route tree on navigations.
  1184. */
  1185. patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
  1186. }
  1187. /**
  1188. * Create a new {@link DataRouter} that manages the application path using an
  1189. * in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
  1190. * stack. Useful for non-browser environments without a DOM API.
  1191. *
  1192. * @public
  1193. * @category Data Routers
  1194. * @mode data
  1195. * @param routes Application routes
  1196. * @param opts Options
  1197. * @param {MemoryRouterOpts.basename} opts.basename n/a
  1198. * @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
  1199. * @param {MemoryRouterOpts.future} opts.future n/a
  1200. * @param {MemoryRouterOpts.getContext} opts.getContext n/a
  1201. * @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
  1202. * @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
  1203. * @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
  1204. * @param {MemoryRouterOpts.unstable_instrumentations} opts.unstable_instrumentations n/a
  1205. * @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
  1206. * @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
  1207. */
  1208. declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router;
  1209. /**
  1210. * Function signature for client side error handling for loader/actions errors
  1211. * and rendering errors via `componentDidCatch`
  1212. */
  1213. interface unstable_ClientOnErrorFunction {
  1214. (error: unknown, info: {
  1215. location: Location;
  1216. params: Params;
  1217. unstable_pattern: string;
  1218. errorInfo?: React.ErrorInfo;
  1219. }): void;
  1220. }
  1221. /**
  1222. * @category Types
  1223. */
  1224. interface RouterProviderProps {
  1225. /**
  1226. * The {@link DataRouter} instance to use for navigation and data fetching.
  1227. */
  1228. router: Router;
  1229. /**
  1230. * The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
  1231. * implementation to use for flushing updates.
  1232. *
  1233. * You usually don't have to worry about this:
  1234. * - The `RouterProvider` exported from `react-router/dom` handles this internally for you
  1235. * - If you are rendering in a non-DOM environment, you can import
  1236. * `RouterProvider` from `react-router` and ignore this prop
  1237. */
  1238. flushSync?: (fn: () => unknown) => undefined;
  1239. /**
  1240. * An error handler function that will be called for any loader/action/render
  1241. * errors that are encountered in your application. This is useful for
  1242. * logging or reporting errors instead of the `ErrorBoundary` because it's not
  1243. * subject to re-rendering and will only run one time per error.
  1244. *
  1245. * The `errorInfo` parameter is passed along from
  1246. * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
  1247. * and is only present for render errors.
  1248. *
  1249. * ```tsx
  1250. * <RouterProvider unstable_onError=(error, errorInfo) => {
  1251. * console.error(error, errorInfo);
  1252. * reportToErrorService(error, errorInfo);
  1253. * }} />
  1254. * ```
  1255. */
  1256. unstable_onError?: unstable_ClientOnErrorFunction;
  1257. /**
  1258. * Control whether router state updates are internally wrapped in
  1259. * [`React.startTransition`](https://react.dev/reference/react/startTransition).
  1260. *
  1261. * - When left `undefined`, all state updates are wrapped in
  1262. * `React.startTransition`
  1263. * - This can lead to buggy behaviors if you are wrapping your own
  1264. * navigations/fetchers in `startTransition`.
  1265. * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
  1266. * in `React.startTransition` and router state changes will be wrapped in
  1267. * `React.startTransition` and also sent through
  1268. * [`useOptimistic`](https://react.dev/reference/react/useOptimistic) to
  1269. * surface mid-navigation router state changes to the UI.
  1270. * - When set to `false`, the router will not leverage `React.startTransition` or
  1271. * `React.useOptimistic` on any navigations or state changes.
  1272. *
  1273. * For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
  1274. */
  1275. unstable_useTransitions?: boolean;
  1276. }
  1277. /**
  1278. * Render the UI for the given {@link DataRouter}. This component should
  1279. * typically be at the top of an app's element tree.
  1280. *
  1281. * ```tsx
  1282. * import { createBrowserRouter } from "react-router";
  1283. * import { RouterProvider } from "react-router/dom";
  1284. * import { createRoot } from "react-dom/client";
  1285. *
  1286. * const router = createBrowserRouter(routes);
  1287. * createRoot(document.getElementById("root")).render(
  1288. * <RouterProvider router={router} />
  1289. * );
  1290. * ```
  1291. *
  1292. * <docs-info>Please note that this component is exported both from
  1293. * `react-router` and `react-router/dom` with the only difference being that the
  1294. * latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
  1295. * implementation. You _almost always_ want to use the version from
  1296. * `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
  1297. *
  1298. *
  1299. * @public
  1300. * @category Data Routers
  1301. * @mode data
  1302. * @param props Props
  1303. * @param {RouterProviderProps.flushSync} props.flushSync n/a
  1304. * @param {RouterProviderProps.unstable_onError} props.unstable_onError n/a
  1305. * @param {RouterProviderProps.router} props.router n/a
  1306. * @param {RouterProviderProps.unstable_useTransitions} props.unstable_useTransitions n/a
  1307. * @returns React element for the rendered router
  1308. */
  1309. declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, unstable_onError, unstable_useTransitions, }: RouterProviderProps): React.ReactElement;
  1310. /**
  1311. * @category Types
  1312. */
  1313. interface MemoryRouterProps {
  1314. /**
  1315. * Application basename
  1316. */
  1317. basename?: string;
  1318. /**
  1319. * Nested {@link Route} elements describing the route tree
  1320. */
  1321. children?: React.ReactNode;
  1322. /**
  1323. * Initial entries in the in-memory history stack
  1324. */
  1325. initialEntries?: InitialEntry[];
  1326. /**
  1327. * Index of `initialEntries` the application should initialize to
  1328. */
  1329. initialIndex?: number;
  1330. /**
  1331. * Control whether router state updates are internally wrapped in
  1332. * [`React.startTransition`](https://react.dev/reference/react/startTransition).
  1333. *
  1334. * - When left `undefined`, all router state updates are wrapped in
  1335. * `React.startTransition`
  1336. * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
  1337. * in `React.startTransition` and all router state updates are wrapped in
  1338. * `React.startTransition`
  1339. * - When set to `false`, the router will not leverage `React.startTransition`
  1340. * on any navigations or state changes.
  1341. *
  1342. * For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
  1343. */
  1344. unstable_useTransitions?: boolean;
  1345. }
  1346. /**
  1347. * A declarative {@link Router | `<Router>`} that stores all entries in memory.
  1348. *
  1349. * @public
  1350. * @category Declarative Routers
  1351. * @mode declarative
  1352. * @param props Props
  1353. * @param {MemoryRouterProps.basename} props.basename n/a
  1354. * @param {MemoryRouterProps.children} props.children n/a
  1355. * @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
  1356. * @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
  1357. * @param {MemoryRouterProps.unstable_useTransitions} props.unstable_useTransitions n/a
  1358. * @returns A declarative in-memory {@link Router | `<Router>`} for client-side
  1359. * routing.
  1360. */
  1361. declare function MemoryRouter({ basename, children, initialEntries, initialIndex, unstable_useTransitions, }: MemoryRouterProps): React.ReactElement;
  1362. /**
  1363. * @category Types
  1364. */
  1365. interface NavigateProps {
  1366. /**
  1367. * The path to navigate to. This can be a string or a {@link Path} object
  1368. */
  1369. to: To;
  1370. /**
  1371. * Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
  1372. * stack
  1373. */
  1374. replace?: boolean;
  1375. /**
  1376. * State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
  1377. */
  1378. state?: any;
  1379. /**
  1380. * How to interpret relative routing in the `to` prop.
  1381. * See {@link RelativeRoutingType}.
  1382. */
  1383. relative?: RelativeRoutingType;
  1384. }
  1385. /**
  1386. * A component-based version of {@link useNavigate} to use in a
  1387. * [`React.Component` class](https://react.dev/reference/react/Component) where
  1388. * hooks cannot be used.
  1389. *
  1390. * It's recommended to avoid using this component in favor of {@link useNavigate}.
  1391. *
  1392. * @example
  1393. * <Navigate to="/tasks" />
  1394. *
  1395. * @public
  1396. * @category Components
  1397. * @param props Props
  1398. * @param {NavigateProps.relative} props.relative n/a
  1399. * @param {NavigateProps.replace} props.replace n/a
  1400. * @param {NavigateProps.state} props.state n/a
  1401. * @param {NavigateProps.to} props.to n/a
  1402. * @returns {void}
  1403. *
  1404. */
  1405. declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
  1406. /**
  1407. * @category Types
  1408. */
  1409. interface OutletProps {
  1410. /**
  1411. * Provides a context value to the element tree below the outlet. Use when
  1412. * the parent route needs to provide values to child routes.
  1413. *
  1414. * ```tsx
  1415. * <Outlet context={myContextValue} />
  1416. * ```
  1417. *
  1418. * Access the context with {@link useOutletContext}.
  1419. */
  1420. context?: unknown;
  1421. }
  1422. /**
  1423. * Renders the matching child route of a parent route or nothing if no child
  1424. * route matches.
  1425. *
  1426. * @example
  1427. * import { Outlet } from "react-router";
  1428. *
  1429. * export default function SomeParent() {
  1430. * return (
  1431. * <div>
  1432. * <h1>Parent Content</h1>
  1433. * <Outlet />
  1434. * </div>
  1435. * );
  1436. * }
  1437. *
  1438. * @public
  1439. * @category Components
  1440. * @param props Props
  1441. * @param {OutletProps.context} props.context n/a
  1442. * @returns React element for the rendered outlet or `null` if no child route matches.
  1443. */
  1444. declare function Outlet(props: OutletProps): React.ReactElement | null;
  1445. /**
  1446. * @category Types
  1447. */
  1448. interface PathRouteProps {
  1449. /**
  1450. * Whether the path should be case-sensitive. Defaults to `false`.
  1451. */
  1452. caseSensitive?: NonIndexRouteObject["caseSensitive"];
  1453. /**
  1454. * The path pattern to match. If unspecified or empty, then this becomes a
  1455. * layout route.
  1456. */
  1457. path?: NonIndexRouteObject["path"];
  1458. /**
  1459. * The unique identifier for this route (for use with {@link DataRouter}s)
  1460. */
  1461. id?: NonIndexRouteObject["id"];
  1462. /**
  1463. * A function that returns a promise that resolves to the route object.
  1464. * Used for code-splitting routes.
  1465. * See [`lazy`](../../start/data/route-object#lazy).
  1466. */
  1467. lazy?: LazyRouteFunction<NonIndexRouteObject>;
  1468. /**
  1469. * The route middleware.
  1470. * See [`middleware`](../../start/data/route-object#middleware).
  1471. */
  1472. middleware?: NonIndexRouteObject["middleware"];
  1473. /**
  1474. * The route loader.
  1475. * See [`loader`](../../start/data/route-object#loader).
  1476. */
  1477. loader?: NonIndexRouteObject["loader"];
  1478. /**
  1479. * The route action.
  1480. * See [`action`](../../start/data/route-object#action).
  1481. */
  1482. action?: NonIndexRouteObject["action"];
  1483. hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
  1484. /**
  1485. * The route shouldRevalidate function.
  1486. * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
  1487. */
  1488. shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
  1489. /**
  1490. * The route handle.
  1491. */
  1492. handle?: NonIndexRouteObject["handle"];
  1493. /**
  1494. * Whether this is an index route.
  1495. */
  1496. index?: false;
  1497. /**
  1498. * Child Route components
  1499. */
  1500. children?: React.ReactNode;
  1501. /**
  1502. * The React element to render when this Route matches.
  1503. * Mutually exclusive with `Component`.
  1504. */
  1505. element?: React.ReactNode | null;
  1506. /**
  1507. * The React element to render while this router is loading data.
  1508. * Mutually exclusive with `HydrateFallback`.
  1509. */
  1510. hydrateFallbackElement?: React.ReactNode | null;
  1511. /**
  1512. * The React element to render at this route if an error occurs.
  1513. * Mutually exclusive with `ErrorBoundary`.
  1514. */
  1515. errorElement?: React.ReactNode | null;
  1516. /**
  1517. * The React Component to render when this route matches.
  1518. * Mutually exclusive with `element`.
  1519. */
  1520. Component?: React.ComponentType | null;
  1521. /**
  1522. * The React Component to render while this router is loading data.
  1523. * Mutually exclusive with `hydrateFallbackElement`.
  1524. */
  1525. HydrateFallback?: React.ComponentType | null;
  1526. /**
  1527. * The React Component to render at this route if an error occurs.
  1528. * Mutually exclusive with `errorElement`.
  1529. */
  1530. ErrorBoundary?: React.ComponentType | null;
  1531. }
  1532. /**
  1533. * @category Types
  1534. */
  1535. interface LayoutRouteProps extends PathRouteProps {
  1536. }
  1537. /**
  1538. * @category Types
  1539. */
  1540. interface IndexRouteProps {
  1541. /**
  1542. * Whether the path should be case-sensitive. Defaults to `false`.
  1543. */
  1544. caseSensitive?: IndexRouteObject["caseSensitive"];
  1545. /**
  1546. * The path pattern to match. If unspecified or empty, then this becomes a
  1547. * layout route.
  1548. */
  1549. path?: IndexRouteObject["path"];
  1550. /**
  1551. * The unique identifier for this route (for use with {@link DataRouter}s)
  1552. */
  1553. id?: IndexRouteObject["id"];
  1554. /**
  1555. * A function that returns a promise that resolves to the route object.
  1556. * Used for code-splitting routes.
  1557. * See [`lazy`](../../start/data/route-object#lazy).
  1558. */
  1559. lazy?: LazyRouteFunction<IndexRouteObject>;
  1560. /**
  1561. * The route middleware.
  1562. * See [`middleware`](../../start/data/route-object#middleware).
  1563. */
  1564. middleware?: IndexRouteObject["middleware"];
  1565. /**
  1566. * The route loader.
  1567. * See [`loader`](../../start/data/route-object#loader).
  1568. */
  1569. loader?: IndexRouteObject["loader"];
  1570. /**
  1571. * The route action.
  1572. * See [`action`](../../start/data/route-object#action).
  1573. */
  1574. action?: IndexRouteObject["action"];
  1575. hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
  1576. /**
  1577. * The route shouldRevalidate function.
  1578. * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
  1579. */
  1580. shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
  1581. /**
  1582. * The route handle.
  1583. */
  1584. handle?: IndexRouteObject["handle"];
  1585. /**
  1586. * Whether this is an index route.
  1587. */
  1588. index: true;
  1589. /**
  1590. * Child Route components
  1591. */
  1592. children?: undefined;
  1593. /**
  1594. * The React element to render when this Route matches.
  1595. * Mutually exclusive with `Component`.
  1596. */
  1597. element?: React.ReactNode | null;
  1598. /**
  1599. * The React element to render while this router is loading data.
  1600. * Mutually exclusive with `HydrateFallback`.
  1601. */
  1602. hydrateFallbackElement?: React.ReactNode | null;
  1603. /**
  1604. * The React element to render at this route if an error occurs.
  1605. * Mutually exclusive with `ErrorBoundary`.
  1606. */
  1607. errorElement?: React.ReactNode | null;
  1608. /**
  1609. * The React Component to render when this route matches.
  1610. * Mutually exclusive with `element`.
  1611. */
  1612. Component?: React.ComponentType | null;
  1613. /**
  1614. * The React Component to render while this router is loading data.
  1615. * Mutually exclusive with `hydrateFallbackElement`.
  1616. */
  1617. HydrateFallback?: React.ComponentType | null;
  1618. /**
  1619. * The React Component to render at this route if an error occurs.
  1620. * Mutually exclusive with `errorElement`.
  1621. */
  1622. ErrorBoundary?: React.ComponentType | null;
  1623. }
  1624. type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
  1625. /**
  1626. * Configures an element to render when a pattern matches the current location.
  1627. * It must be rendered within a {@link Routes} element. Note that these routes
  1628. * do not participate in data loading, actions, code splitting, or any other
  1629. * route module features.
  1630. *
  1631. * @example
  1632. * // Usually used in a declarative router
  1633. * function App() {
  1634. * return (
  1635. * <BrowserRouter>
  1636. * <Routes>
  1637. * <Route index element={<StepOne />} />
  1638. * <Route path="step-2" element={<StepTwo />} />
  1639. * <Route path="step-3" element={<StepThree />} />
  1640. * </Routes>
  1641. * </BrowserRouter>
  1642. * );
  1643. * }
  1644. *
  1645. * // But can be used with a data router as well if you prefer the JSX notation
  1646. * const routes = createRoutesFromElements(
  1647. * <>
  1648. * <Route index loader={step1Loader} Component={StepOne} />
  1649. * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
  1650. * <Route path="step-3" loader={step3Loader} Component={StepThree} />
  1651. * </>
  1652. * );
  1653. *
  1654. * const router = createBrowserRouter(routes);
  1655. *
  1656. * function App() {
  1657. * return <RouterProvider router={router} />;
  1658. * }
  1659. *
  1660. * @public
  1661. * @category Components
  1662. * @param props Props
  1663. * @param {PathRouteProps.action} props.action n/a
  1664. * @param {PathRouteProps.caseSensitive} props.caseSensitive n/a
  1665. * @param {PathRouteProps.Component} props.Component n/a
  1666. * @param {PathRouteProps.children} props.children n/a
  1667. * @param {PathRouteProps.element} props.element n/a
  1668. * @param {PathRouteProps.ErrorBoundary} props.ErrorBoundary n/a
  1669. * @param {PathRouteProps.errorElement} props.errorElement n/a
  1670. * @param {PathRouteProps.handle} props.handle n/a
  1671. * @param {PathRouteProps.HydrateFallback} props.HydrateFallback n/a
  1672. * @param {PathRouteProps.hydrateFallbackElement} props.hydrateFallbackElement n/a
  1673. * @param {PathRouteProps.id} props.id n/a
  1674. * @param {PathRouteProps.index} props.index n/a
  1675. * @param {PathRouteProps.lazy} props.lazy n/a
  1676. * @param {PathRouteProps.loader} props.loader n/a
  1677. * @param {PathRouteProps.path} props.path n/a
  1678. * @param {PathRouteProps.shouldRevalidate} props.shouldRevalidate n/a
  1679. * @returns {void}
  1680. */
  1681. declare function Route(props: RouteProps): React.ReactElement | null;
  1682. /**
  1683. * @category Types
  1684. */
  1685. interface RouterProps {
  1686. /**
  1687. * The base path for the application. This is prepended to all locations
  1688. */
  1689. basename?: string;
  1690. /**
  1691. * Nested {@link Route} elements describing the route tree
  1692. */
  1693. children?: React.ReactNode;
  1694. /**
  1695. * The location to match against. Defaults to the current location.
  1696. * This can be a string or a {@link Location} object.
  1697. */
  1698. location: Partial<Location> | string;
  1699. /**
  1700. * The type of navigation that triggered this `location` change.
  1701. * Defaults to {@link NavigationType.Pop}.
  1702. */
  1703. navigationType?: Action;
  1704. /**
  1705. * The navigator to use for navigation. This is usually a history object
  1706. * or a custom navigator that implements the {@link Navigator} interface.
  1707. */
  1708. navigator: Navigator;
  1709. /**
  1710. * Whether this router is static or not (used for SSR). If `true`, the router
  1711. * will not be reactive to location changes.
  1712. */
  1713. static?: boolean;
  1714. /**
  1715. * Whether this router should wrap navigations in `React.startTransition()`
  1716. */
  1717. unstable_useTransitions: boolean;
  1718. }
  1719. /**
  1720. * Provides location context for the rest of the app.
  1721. *
  1722. * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
  1723. * router that is more specific to your environment such as a {@link BrowserRouter}
  1724. * in web browsers or a {@link ServerRouter} for server rendering.
  1725. *
  1726. * @public
  1727. * @category Declarative Routers
  1728. * @mode declarative
  1729. * @param props Props
  1730. * @param {RouterProps.basename} props.basename n/a
  1731. * @param {RouterProps.children} props.children n/a
  1732. * @param {RouterProps.location} props.location n/a
  1733. * @param {RouterProps.navigationType} props.navigationType n/a
  1734. * @param {RouterProps.navigator} props.navigator n/a
  1735. * @param {RouterProps.static} props.static n/a
  1736. * @param {RouterProps.unstable_useTransitions} props.unstable_useTransitions n/a
  1737. * @returns React element for the rendered router or `null` if the location does
  1738. * not match the {@link props.basename}
  1739. */
  1740. declare function Router$1({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, unstable_useTransitions, }: RouterProps): React.ReactElement | null;
  1741. /**
  1742. * @category Types
  1743. */
  1744. interface RoutesProps {
  1745. /**
  1746. * Nested {@link Route} elements
  1747. */
  1748. children?: React.ReactNode;
  1749. /**
  1750. * The {@link Location} to match against. Defaults to the current location.
  1751. */
  1752. location?: Partial<Location> | string;
  1753. }
  1754. /**
  1755. * Renders a branch of {@link Route | `<Route>`s} that best matches the current
  1756. * location. Note that these routes do not participate in [data loading](../../start/framework/route-module#loader),
  1757. * [`action`](../../start/framework/route-module#action), code splitting, or
  1758. * any other [route module](../../start/framework/route-module) features.
  1759. *
  1760. * @example
  1761. * import { Route, Routes } from "react-router";
  1762. *
  1763. * <Routes>
  1764. * <Route index element={<StepOne />} />
  1765. * <Route path="step-2" element={<StepTwo />} />
  1766. * <Route path="step-3" element={<StepThree />} />
  1767. * </Routes>
  1768. *
  1769. * @public
  1770. * @category Components
  1771. * @param props Props
  1772. * @param {RoutesProps.children} props.children n/a
  1773. * @param {RoutesProps.location} props.location n/a
  1774. * @returns React element for the rendered routes or `null` if no route matches
  1775. */
  1776. declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
  1777. interface AwaitResolveRenderFunction<Resolve = any> {
  1778. (data: Awaited<Resolve>): React.ReactNode;
  1779. }
  1780. /**
  1781. * @category Types
  1782. */
  1783. interface AwaitProps<Resolve> {
  1784. /**
  1785. * When using a function, the resolved value is provided as the parameter.
  1786. *
  1787. * ```tsx [2]
  1788. * <Await resolve={reviewsPromise}>
  1789. * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
  1790. * </Await>
  1791. * ```
  1792. *
  1793. * When using React elements, {@link useAsyncValue} will provide the
  1794. * resolved value:
  1795. *
  1796. * ```tsx [2]
  1797. * <Await resolve={reviewsPromise}>
  1798. * <Reviews />
  1799. * </Await>
  1800. *
  1801. * function Reviews() {
  1802. * const resolvedReviews = useAsyncValue();
  1803. * return <div>...</div>;
  1804. * }
  1805. * ```
  1806. */
  1807. children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
  1808. /**
  1809. * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
  1810. * rejects.
  1811. *
  1812. * ```tsx
  1813. * <Await
  1814. * errorElement={<div>Oops</div>}
  1815. * resolve={reviewsPromise}
  1816. * >
  1817. * <Reviews />
  1818. * </Await>
  1819. * ```
  1820. *
  1821. * To provide a more contextual error, you can use the {@link useAsyncError} in a
  1822. * child component
  1823. *
  1824. * ```tsx
  1825. * <Await
  1826. * errorElement={<ReviewsError />}
  1827. * resolve={reviewsPromise}
  1828. * >
  1829. * <Reviews />
  1830. * </Await>
  1831. *
  1832. * function ReviewsError() {
  1833. * const error = useAsyncError();
  1834. * return <div>Error loading reviews: {error.message}</div>;
  1835. * }
  1836. * ```
  1837. *
  1838. * If you do not provide an `errorElement`, the rejected value will bubble up
  1839. * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
  1840. * and be accessible via the {@link useRouteError} hook.
  1841. */
  1842. errorElement?: React.ReactNode;
  1843. /**
  1844. * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
  1845. * returned from a [`loader`](../../start/framework/route-module#loader) to be
  1846. * resolved and rendered.
  1847. *
  1848. * ```tsx
  1849. * import { Await, useLoaderData } from "react-router";
  1850. *
  1851. * export async function loader() {
  1852. * let reviews = getReviews(); // not awaited
  1853. * let book = await getBook();
  1854. * return {
  1855. * book,
  1856. * reviews, // this is a promise
  1857. * };
  1858. * }
  1859. *
  1860. * export default function Book() {
  1861. * const {
  1862. * book,
  1863. * reviews, // this is the same promise
  1864. * } = useLoaderData();
  1865. *
  1866. * return (
  1867. * <div>
  1868. * <h1>{book.title}</h1>
  1869. * <p>{book.description}</p>
  1870. * <React.Suspense fallback={<ReviewsSkeleton />}>
  1871. * <Await
  1872. * // and is the promise we pass to Await
  1873. * resolve={reviews}
  1874. * >
  1875. * <Reviews />
  1876. * </Await>
  1877. * </React.Suspense>
  1878. * </div>
  1879. * );
  1880. * }
  1881. * ```
  1882. */
  1883. resolve: Resolve;
  1884. }
  1885. /**
  1886. * Used to render promise values with automatic error handling.
  1887. *
  1888. * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
  1889. *
  1890. * @example
  1891. * import { Await, useLoaderData } from "react-router";
  1892. *
  1893. * export async function loader() {
  1894. * // not awaited
  1895. * const reviews = getReviews();
  1896. * // awaited (blocks the transition)
  1897. * const book = await fetch("/api/book").then((res) => res.json());
  1898. * return { book, reviews };
  1899. * }
  1900. *
  1901. * function Book() {
  1902. * const { book, reviews } = useLoaderData();
  1903. * return (
  1904. * <div>
  1905. * <h1>{book.title}</h1>
  1906. * <p>{book.description}</p>
  1907. * <React.Suspense fallback={<ReviewsSkeleton />}>
  1908. * <Await
  1909. * resolve={reviews}
  1910. * errorElement={
  1911. * <div>Could not load reviews 😬</div>
  1912. * }
  1913. * children={(resolvedReviews) => (
  1914. * <Reviews items={resolvedReviews} />
  1915. * )}
  1916. * />
  1917. * </React.Suspense>
  1918. * </div>
  1919. * );
  1920. * }
  1921. *
  1922. * @public
  1923. * @category Components
  1924. * @mode framework
  1925. * @mode data
  1926. * @param props Props
  1927. * @param {AwaitProps.children} props.children n/a
  1928. * @param {AwaitProps.errorElement} props.errorElement n/a
  1929. * @param {AwaitProps.resolve} props.resolve n/a
  1930. * @returns React element for the rendered awaited value
  1931. */
  1932. declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
  1933. /**
  1934. * Creates a route config from a React "children" object, which is usually
  1935. * either a `<Route>` element or an array of them. Used internally by
  1936. * `<Routes>` to create a route config from its children.
  1937. *
  1938. * @category Utils
  1939. * @mode data
  1940. * @param children The React children to convert into a route config
  1941. * @param parentPath The path of the parent route, used to generate unique IDs.
  1942. * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
  1943. */
  1944. declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
  1945. /**
  1946. * Create route objects from JSX elements instead of arrays of objects.
  1947. *
  1948. * @example
  1949. * const routes = createRoutesFromElements(
  1950. * <>
  1951. * <Route index loader={step1Loader} Component={StepOne} />
  1952. * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
  1953. * <Route path="step-3" loader={step3Loader} Component={StepThree} />
  1954. * </>
  1955. * );
  1956. *
  1957. * const router = createBrowserRouter(routes);
  1958. *
  1959. * function App() {
  1960. * return <RouterProvider router={router} />;
  1961. * }
  1962. *
  1963. * @name createRoutesFromElements
  1964. * @public
  1965. * @category Utils
  1966. * @mode data
  1967. * @param children The React children to convert into a route config
  1968. * @param parentPath The path of the parent route, used to generate unique IDs.
  1969. * This is used for internal recursion and is not intended to be used by the
  1970. * application developer.
  1971. * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
  1972. */
  1973. declare const createRoutesFromElements: typeof createRoutesFromChildren;
  1974. /**
  1975. * Renders the result of {@link matchRoutes} into a React element.
  1976. *
  1977. * @public
  1978. * @category Utils
  1979. * @param matches The array of {@link RouteMatch | route matches} to render
  1980. * @returns A React element that renders the matched routes or `null` if no matches
  1981. */
  1982. declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
  1983. declare function useRouteComponentProps(): {
  1984. params: Readonly<Params<string>>;
  1985. loaderData: any;
  1986. actionData: any;
  1987. matches: UIMatch<unknown, unknown>[];
  1988. };
  1989. type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
  1990. type RouteComponentType = React.ComponentType<RouteComponentProps>;
  1991. declare function WithComponentProps({ children, }: {
  1992. children: React.ReactElement;
  1993. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  1994. declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
  1995. params: Readonly<Params<string>>;
  1996. loaderData: any;
  1997. actionData: any;
  1998. matches: UIMatch<unknown, unknown>[];
  1999. }, string | React.JSXElementConstructor<any>>;
  2000. declare function useHydrateFallbackProps(): {
  2001. params: Readonly<Params<string>>;
  2002. loaderData: any;
  2003. actionData: any;
  2004. };
  2005. type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
  2006. type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
  2007. declare function WithHydrateFallbackProps({ children, }: {
  2008. children: React.ReactElement;
  2009. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  2010. declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
  2011. params: Readonly<Params<string>>;
  2012. loaderData: any;
  2013. actionData: any;
  2014. }, string | React.JSXElementConstructor<any>>;
  2015. declare function useErrorBoundaryProps(): {
  2016. params: Readonly<Params<string>>;
  2017. loaderData: any;
  2018. actionData: any;
  2019. error: unknown;
  2020. };
  2021. type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
  2022. type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
  2023. declare function WithErrorBoundaryProps({ children, }: {
  2024. children: React.ReactElement;
  2025. }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
  2026. declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
  2027. params: Readonly<Params<string>>;
  2028. loaderData: any;
  2029. actionData: any;
  2030. error: unknown;
  2031. }, string | React.JSXElementConstructor<any>>;
  2032. interface IndexRouteObject {
  2033. caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
  2034. path?: AgnosticIndexRouteObject["path"];
  2035. id?: AgnosticIndexRouteObject["id"];
  2036. middleware?: AgnosticIndexRouteObject["middleware"];
  2037. loader?: AgnosticIndexRouteObject["loader"];
  2038. action?: AgnosticIndexRouteObject["action"];
  2039. hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
  2040. shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
  2041. handle?: AgnosticIndexRouteObject["handle"];
  2042. index: true;
  2043. children?: undefined;
  2044. element?: React.ReactNode | null;
  2045. hydrateFallbackElement?: React.ReactNode | null;
  2046. errorElement?: React.ReactNode | null;
  2047. Component?: React.ComponentType | null;
  2048. HydrateFallback?: React.ComponentType | null;
  2049. ErrorBoundary?: React.ComponentType | null;
  2050. lazy?: LazyRouteDefinition<RouteObject>;
  2051. }
  2052. interface NonIndexRouteObject {
  2053. caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
  2054. path?: AgnosticNonIndexRouteObject["path"];
  2055. id?: AgnosticNonIndexRouteObject["id"];
  2056. middleware?: AgnosticNonIndexRouteObject["middleware"];
  2057. loader?: AgnosticNonIndexRouteObject["loader"];
  2058. action?: AgnosticNonIndexRouteObject["action"];
  2059. hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
  2060. shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
  2061. handle?: AgnosticNonIndexRouteObject["handle"];
  2062. index?: false;
  2063. children?: RouteObject[];
  2064. element?: React.ReactNode | null;
  2065. hydrateFallbackElement?: React.ReactNode | null;
  2066. errorElement?: React.ReactNode | null;
  2067. Component?: React.ComponentType | null;
  2068. HydrateFallback?: React.ComponentType | null;
  2069. ErrorBoundary?: React.ComponentType | null;
  2070. lazy?: LazyRouteDefinition<RouteObject>;
  2071. }
  2072. type RouteObject = IndexRouteObject | NonIndexRouteObject;
  2073. type DataRouteObject = RouteObject & {
  2074. children?: DataRouteObject[];
  2075. id: string;
  2076. };
  2077. interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
  2078. }
  2079. interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
  2080. }
  2081. type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
  2082. type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
  2083. interface DataRouterContextObject extends Omit<NavigationContextObject, "future" | "unstable_useTransitions"> {
  2084. router: Router;
  2085. staticContext?: StaticHandlerContext;
  2086. unstable_onError?: unstable_ClientOnErrorFunction;
  2087. }
  2088. declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
  2089. declare const DataRouterStateContext: React.Context<RouterState | null>;
  2090. type ViewTransitionContextObject = {
  2091. isTransitioning: false;
  2092. } | {
  2093. isTransitioning: true;
  2094. flushSync: boolean;
  2095. currentLocation: Location;
  2096. nextLocation: Location;
  2097. };
  2098. declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
  2099. type FetchersContextObject = Map<string, any>;
  2100. declare const FetchersContext: React.Context<FetchersContextObject>;
  2101. declare const AwaitContext: React.Context<TrackedPromise | null>;
  2102. declare const AwaitContextProvider: (props: React.ComponentProps<typeof AwaitContext.Provider>) => React.FunctionComponentElement<React.ProviderProps<TrackedPromise | null>>;
  2103. interface NavigateOptions {
  2104. /** Replace the current entry in the history stack instead of pushing a new one */
  2105. replace?: boolean;
  2106. /** Adds persistent client side routing state to the next location */
  2107. state?: any;
  2108. /** 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 */
  2109. preventScrollReset?: boolean;
  2110. /** 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. */
  2111. relative?: RelativeRoutingType;
  2112. /** 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} */
  2113. flushSync?: boolean;
  2114. /** 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. */
  2115. viewTransition?: boolean;
  2116. }
  2117. /**
  2118. * A Navigator is a "location changer"; it's how you get to different locations.
  2119. *
  2120. * Every history instance conforms to the Navigator interface, but the
  2121. * distinction is useful primarily when it comes to the low-level `<Router>` API
  2122. * where both the location and a navigator must be provided separately in order
  2123. * to avoid "tearing" that may occur in a suspense-enabled app if the action
  2124. * and/or location were to be read directly from the history instance.
  2125. */
  2126. interface Navigator {
  2127. createHref: History["createHref"];
  2128. encodeLocation?: History["encodeLocation"];
  2129. go: History["go"];
  2130. push(to: To, state?: any, opts?: NavigateOptions): void;
  2131. replace(to: To, state?: any, opts?: NavigateOptions): void;
  2132. }
  2133. interface NavigationContextObject {
  2134. basename: string;
  2135. navigator: Navigator;
  2136. static: boolean;
  2137. unstable_useTransitions: boolean;
  2138. future: {};
  2139. }
  2140. declare const NavigationContext: React.Context<NavigationContextObject>;
  2141. interface LocationContextObject {
  2142. location: Location;
  2143. navigationType: Action;
  2144. }
  2145. declare const LocationContext: React.Context<LocationContextObject>;
  2146. interface RouteContextObject {
  2147. outlet: React.ReactElement | null;
  2148. matches: RouteMatch[];
  2149. isDataRoute: boolean;
  2150. }
  2151. declare const RouteContext: React.Context<RouteContextObject>;
  2152. type Primitive = null | undefined | string | number | boolean | symbol | bigint;
  2153. type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
  2154. interface HtmlLinkProps {
  2155. /**
  2156. * Address of the hyperlink
  2157. */
  2158. href?: string;
  2159. /**
  2160. * How the element handles crossorigin requests
  2161. */
  2162. crossOrigin?: "anonymous" | "use-credentials";
  2163. /**
  2164. * Relationship between the document containing the hyperlink and the destination resource
  2165. */
  2166. rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
  2167. /**
  2168. * Applicable media: "screen", "print", "(max-width: 764px)"
  2169. */
  2170. media?: string;
  2171. /**
  2172. * Integrity metadata used in Subresource Integrity checks
  2173. */
  2174. integrity?: string;
  2175. /**
  2176. * Language of the linked resource
  2177. */
  2178. hrefLang?: string;
  2179. /**
  2180. * Hint for the type of the referenced resource
  2181. */
  2182. type?: string;
  2183. /**
  2184. * Referrer policy for fetches initiated by the element
  2185. */
  2186. referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
  2187. /**
  2188. * Sizes of the icons (for rel="icon")
  2189. */
  2190. sizes?: string;
  2191. /**
  2192. * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
  2193. */
  2194. as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
  2195. /**
  2196. * Color to use when customizing a site's icon (for rel="mask-icon")
  2197. */
  2198. color?: string;
  2199. /**
  2200. * Whether the link is disabled
  2201. */
  2202. disabled?: boolean;
  2203. /**
  2204. * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
  2205. */
  2206. title?: string;
  2207. /**
  2208. * Images to use in different situations, e.g., high-resolution displays,
  2209. * small monitors, etc. (for rel="preload")
  2210. */
  2211. imageSrcSet?: string;
  2212. /**
  2213. * Image sizes for different page layouts (for rel="preload")
  2214. */
  2215. imageSizes?: string;
  2216. }
  2217. interface HtmlLinkPreloadImage extends HtmlLinkProps {
  2218. /**
  2219. * Relationship between the document containing the hyperlink and the destination resource
  2220. */
  2221. rel: "preload";
  2222. /**
  2223. * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
  2224. */
  2225. as: "image";
  2226. /**
  2227. * Address of the hyperlink
  2228. */
  2229. href?: string;
  2230. /**
  2231. * Images to use in different situations, e.g., high-resolution displays,
  2232. * small monitors, etc. (for rel="preload")
  2233. */
  2234. imageSrcSet: string;
  2235. /**
  2236. * Image sizes for different page layouts (for rel="preload")
  2237. */
  2238. imageSizes?: string;
  2239. }
  2240. /**
  2241. * Represents a `<link>` element.
  2242. *
  2243. * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
  2244. */
  2245. type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
  2246. imageSizes?: never;
  2247. });
  2248. interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
  2249. /**
  2250. * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
  2251. * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
  2252. * element
  2253. */
  2254. nonce?: string | undefined;
  2255. /**
  2256. * The absolute path of the page to prefetch, e.g. `/absolute/path`.
  2257. */
  2258. page: string;
  2259. }
  2260. type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
  2261. type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
  2262. [key: PropertyKey]: Serializable;
  2263. } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
  2264. type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
  2265. type IsAny<T> = 0 extends 1 & T ? true : false;
  2266. type Func = (...args: any[]) => unknown;
  2267. type Pretty<T> = {
  2268. [K in keyof T]: T[K];
  2269. } & {};
  2270. type Normalize<T> = _Normalize<UnionKeys<T>, T>;
  2271. type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
  2272. [K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
  2273. } & {
  2274. [K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
  2275. } & {
  2276. [K in Key as K extends keyof U ? never : K]?: undefined;
  2277. }> : never;
  2278. type UnionKeys<T> = T extends any ? keyof T : never;
  2279. type RouteModule$1 = {
  2280. meta?: Func;
  2281. links?: Func;
  2282. headers?: Func;
  2283. loader?: Func;
  2284. clientLoader?: Func;
  2285. action?: Func;
  2286. clientAction?: Func;
  2287. HydrateFallback?: Func;
  2288. default?: Func;
  2289. ErrorBoundary?: Func;
  2290. [key: string]: unknown;
  2291. };
  2292. /**
  2293. * A brand that can be applied to a type to indicate that it will serialize
  2294. * to a specific type when transported to the client from a loader.
  2295. * Only use this if you have additional serialization/deserialization logic
  2296. * in your application.
  2297. */
  2298. type unstable_SerializesTo<T> = {
  2299. unstable__ReactRouter_SerializesTo: [T];
  2300. };
  2301. 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> ? {
  2302. [K in keyof T]: Serialize<T[K]>;
  2303. } : undefined;
  2304. type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
  2305. type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
  2306. type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
  2307. type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
  2308. type ServerDataFrom<T> = ServerData<DataFrom<T>>;
  2309. type ClientDataFrom<T> = ClientData<DataFrom<T>>;
  2310. type ClientDataFunctionArgs<Params> = {
  2311. /**
  2312. * 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.
  2313. *
  2314. * @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.
  2315. **/
  2316. request: Request;
  2317. /**
  2318. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
  2319. * @example
  2320. * // app/routes.ts
  2321. * route("teams/:teamId", "./team.tsx"),
  2322. *
  2323. * // app/team.tsx
  2324. * export function clientLoader({
  2325. * params,
  2326. * }: Route.ClientLoaderArgs) {
  2327. * params.teamId;
  2328. * // ^ string
  2329. * }
  2330. **/
  2331. params: Params;
  2332. /**
  2333. * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
  2334. * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
  2335. */
  2336. unstable_pattern: string;
  2337. /**
  2338. * When `future.v8_middleware` is not enabled, this is undefined.
  2339. *
  2340. * When `future.v8_middleware` is enabled, this is an instance of
  2341. * `RouterContextProvider` and can be used to access context values
  2342. * from your route middlewares. You may pass in initial context values in your
  2343. * `<HydratedRouter getContext>` prop
  2344. */
  2345. context: Readonly<RouterContextProvider>;
  2346. };
  2347. type ServerDataFunctionArgs<Params> = {
  2348. /** 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. */
  2349. request: Request;
  2350. /**
  2351. * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
  2352. * @example
  2353. * // app/routes.ts
  2354. * route("teams/:teamId", "./team.tsx"),
  2355. *
  2356. * // app/team.tsx
  2357. * export function loader({
  2358. * params,
  2359. * }: Route.LoaderArgs) {
  2360. * params.teamId;
  2361. * // ^ string
  2362. * }
  2363. **/
  2364. params: Params;
  2365. /**
  2366. * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
  2367. * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
  2368. */
  2369. unstable_pattern: string;
  2370. /**
  2371. * Without `future.v8_middleware` enabled, this is the context passed in
  2372. * to your server adapter's `getLoadContext` function. It's a way to bridge the
  2373. * gap between the adapter's request/response API with your React Router app.
  2374. * It is only applicable if you are using a custom server adapter.
  2375. *
  2376. * With `future.v8_middleware` enabled, this is an instance of
  2377. * `RouterContextProvider` and can be used for type-safe access to
  2378. * context value set in your route middlewares. If you are using a custom
  2379. * server adapter, you may provide an initial set of context values from your
  2380. * `getLoadContext` function.
  2381. */
  2382. context: MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : AppLoadContext;
  2383. };
  2384. type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
  2385. ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
  2386. ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
  2387. type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
  2388. type IsHydrate<ClientLoader> = ClientLoader extends {
  2389. hydrate: true;
  2390. } ? true : ClientLoader extends {
  2391. hydrate: false;
  2392. } ? false : false;
  2393. type GetLoaderData<T extends RouteModule$1> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
  2394. HydrateFallback: Func;
  2395. } ? true : false>;
  2396. type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
  2397. HasHydrateFallback,
  2398. ClientLoaderHydrate
  2399. ] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
  2400. IsDefined<ClientLoaderData>,
  2401. IsDefined<ServerLoaderData>
  2402. ] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
  2403. type GetActionData<T extends RouteModule$1> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
  2404. type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
  2405. IsDefined<ServerActionData>,
  2406. IsDefined<ClientActionData>
  2407. ] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
  2408. interface RouteModules {
  2409. [routeId: string]: RouteModule | undefined;
  2410. }
  2411. /**
  2412. * The shape of a route module shipped to the client
  2413. */
  2414. interface RouteModule {
  2415. clientAction?: ClientActionFunction;
  2416. clientLoader?: ClientLoaderFunction;
  2417. clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
  2418. ErrorBoundary?: ErrorBoundaryComponent;
  2419. HydrateFallback?: HydrateFallbackComponent;
  2420. Layout?: LayoutComponent;
  2421. default: RouteComponent;
  2422. handle?: RouteHandle;
  2423. links?: LinksFunction;
  2424. meta?: MetaFunction;
  2425. shouldRevalidate?: ShouldRevalidateFunction;
  2426. }
  2427. /**
  2428. * The shape of a route module on the server
  2429. */
  2430. interface ServerRouteModule extends RouteModule {
  2431. action?: ActionFunction;
  2432. headers?: HeadersFunction | {
  2433. [name: string]: string;
  2434. };
  2435. loader?: LoaderFunction;
  2436. middleware?: MiddlewareFunction<Response>[];
  2437. }
  2438. /**
  2439. * A function that handles data mutations for a route on the client
  2440. */
  2441. type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
  2442. /**
  2443. * Arguments passed to a route `clientAction` function
  2444. */
  2445. type ClientActionFunctionArgs = ActionFunctionArgs & {
  2446. serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
  2447. };
  2448. /**
  2449. * A function that loads data for a route on the client
  2450. */
  2451. type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
  2452. hydrate?: boolean;
  2453. };
  2454. /**
  2455. * Arguments passed to a route `clientLoader` function
  2456. */
  2457. type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
  2458. serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
  2459. };
  2460. /**
  2461. * ErrorBoundary to display for this route
  2462. */
  2463. type ErrorBoundaryComponent = ComponentType;
  2464. type HeadersArgs = {
  2465. loaderHeaders: Headers;
  2466. parentHeaders: Headers;
  2467. actionHeaders: Headers;
  2468. errorHeaders: Headers | undefined;
  2469. };
  2470. /**
  2471. * A function that returns HTTP headers to be used for a route. These headers
  2472. * will be merged with (and take precedence over) headers from parent routes.
  2473. */
  2474. interface HeadersFunction {
  2475. (args: HeadersArgs): Headers | HeadersInit;
  2476. }
  2477. /**
  2478. * `<Route HydrateFallback>` component to render on initial loads
  2479. * when client loaders are present
  2480. */
  2481. type HydrateFallbackComponent = ComponentType;
  2482. /**
  2483. * Optional, root-only `<Route Layout>` component to wrap the root content in.
  2484. * Useful for defining the <html>/<head>/<body> document shell shared by the
  2485. * Component, HydrateFallback, and ErrorBoundary
  2486. */
  2487. type LayoutComponent = ComponentType<{
  2488. children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
  2489. }>;
  2490. /**
  2491. * A function that defines `<link>` tags to be inserted into the `<head>` of
  2492. * the document on route transitions.
  2493. *
  2494. * @see https://reactrouter.com/start/framework/route-module#meta
  2495. */
  2496. interface LinksFunction {
  2497. (): LinkDescriptor[];
  2498. }
  2499. interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
  2500. id: RouteId;
  2501. pathname: DataRouteMatch["pathname"];
  2502. /** @deprecated Use `MetaMatch.loaderData` instead */
  2503. data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
  2504. loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
  2505. handle?: RouteHandle;
  2506. params: DataRouteMatch["params"];
  2507. meta: MetaDescriptor[];
  2508. error?: unknown;
  2509. }
  2510. type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
  2511. [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
  2512. }[keyof MatchLoaders]>;
  2513. interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
  2514. /** @deprecated Use `MetaArgs.loaderData` instead */
  2515. data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
  2516. loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
  2517. params: Params;
  2518. location: Location;
  2519. matches: MetaMatches<MatchLoaders>;
  2520. error?: unknown;
  2521. }
  2522. /**
  2523. * A function that returns an array of data objects to use for rendering
  2524. * metadata HTML tags in a route. These tags are not rendered on descendant
  2525. * routes in the route hierarchy. In other words, they will only be rendered on
  2526. * the route in which they are exported.
  2527. *
  2528. * @param Loader - The type of the current route's loader function
  2529. * @param MatchLoaders - Mapping from a parent route's filepath to its loader
  2530. * function type
  2531. *
  2532. * Note that parent route filepaths are relative to the `app/` directory.
  2533. *
  2534. * For example, if this meta function is for `/sales/customers/$customerId`:
  2535. *
  2536. * ```ts
  2537. * // app/root.tsx
  2538. * const loader = () => ({ hello: "world" })
  2539. * export type Loader = typeof loader
  2540. *
  2541. * // app/routes/sales.tsx
  2542. * const loader = () => ({ salesCount: 1074 })
  2543. * export type Loader = typeof loader
  2544. *
  2545. * // app/routes/sales/customers.tsx
  2546. * const loader = () => ({ customerCount: 74 })
  2547. * export type Loader = typeof loader
  2548. *
  2549. * // app/routes/sales/customers/$customersId.tsx
  2550. * import type { Loader as RootLoader } from "../../../root"
  2551. * import type { Loader as SalesLoader } from "../../sales"
  2552. * import type { Loader as CustomersLoader } from "../../sales/customers"
  2553. *
  2554. * const loader = () => ({ name: "Customer name" })
  2555. *
  2556. * const meta: MetaFunction<typeof loader, {
  2557. * "root": RootLoader,
  2558. * "routes/sales": SalesLoader,
  2559. * "routes/sales/customers": CustomersLoader,
  2560. * }> = ({ data, matches }) => {
  2561. * const { name } = data
  2562. * // ^? string
  2563. * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
  2564. * // ^? number
  2565. * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
  2566. * // ^? number
  2567. * const { hello } = matches.find((match) => match.id === "root").data
  2568. * // ^? "world"
  2569. * }
  2570. * ```
  2571. */
  2572. interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
  2573. (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
  2574. }
  2575. type MetaDescriptor = {
  2576. charSet: "utf-8";
  2577. } | {
  2578. title: string;
  2579. } | {
  2580. name: string;
  2581. content: string;
  2582. } | {
  2583. property: string;
  2584. content: string;
  2585. } | {
  2586. httpEquiv: string;
  2587. content: string;
  2588. } | {
  2589. "script:ld+json": LdJsonObject;
  2590. } | {
  2591. tagName: "meta" | "link";
  2592. [name: string]: string;
  2593. } | {
  2594. [name: string]: unknown;
  2595. };
  2596. type LdJsonObject = {
  2597. [Key in string]: LdJsonValue;
  2598. } & {
  2599. [Key in string]?: LdJsonValue | undefined;
  2600. };
  2601. type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
  2602. type LdJsonPrimitive = string | number | boolean | null;
  2603. type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
  2604. /**
  2605. * A React component that is rendered for a route.
  2606. */
  2607. type RouteComponent = ComponentType<{}>;
  2608. /**
  2609. * An arbitrary object that is associated with a route.
  2610. *
  2611. * @see https://reactrouter.com/how-to/using-handle
  2612. */
  2613. type RouteHandle = unknown;
  2614. type unstable_ServerInstrumentation = {
  2615. handler?: unstable_InstrumentRequestHandlerFunction;
  2616. route?: unstable_InstrumentRouteFunction;
  2617. };
  2618. type unstable_ClientInstrumentation = {
  2619. router?: unstable_InstrumentRouterFunction;
  2620. route?: unstable_InstrumentRouteFunction;
  2621. };
  2622. type unstable_InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
  2623. type unstable_InstrumentRouterFunction = (router: InstrumentableRouter) => void;
  2624. type unstable_InstrumentRouteFunction = (route: InstrumentableRoute) => void;
  2625. type unstable_InstrumentationHandlerResult = {
  2626. status: "success";
  2627. error: undefined;
  2628. } | {
  2629. status: "error";
  2630. error: Error;
  2631. };
  2632. type InstrumentFunction<T> = (handler: () => Promise<unstable_InstrumentationHandlerResult>, info: T) => Promise<void>;
  2633. type ReadonlyRequest = {
  2634. method: string;
  2635. url: string;
  2636. headers: Pick<Headers, "get">;
  2637. };
  2638. type ReadonlyContext = MiddlewareEnabled extends true ? Pick<RouterContextProvider, "get"> : Readonly<AppLoadContext>;
  2639. type InstrumentableRoute = {
  2640. id: string;
  2641. index: boolean | undefined;
  2642. path: string | undefined;
  2643. instrument(instrumentations: RouteInstrumentations): void;
  2644. };
  2645. type RouteInstrumentations = {
  2646. lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  2647. "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  2648. "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  2649. "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
  2650. middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  2651. loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  2652. action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
  2653. };
  2654. type RouteLazyInstrumentationInfo = undefined;
  2655. type RouteHandlerInstrumentationInfo = Readonly<{
  2656. request: ReadonlyRequest;
  2657. params: LoaderFunctionArgs["params"];
  2658. unstable_pattern: string;
  2659. context: ReadonlyContext;
  2660. }>;
  2661. type InstrumentableRouter = {
  2662. instrument(instrumentations: RouterInstrumentations): void;
  2663. };
  2664. type RouterInstrumentations = {
  2665. navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
  2666. fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
  2667. };
  2668. type RouterNavigationInstrumentationInfo = Readonly<{
  2669. to: string | number;
  2670. currentUrl: string;
  2671. formMethod?: HTMLFormMethod;
  2672. formEncType?: FormEncType;
  2673. formData?: FormData;
  2674. body?: any;
  2675. }>;
  2676. type RouterFetchInstrumentationInfo = Readonly<{
  2677. href: string;
  2678. currentUrl: string;
  2679. fetcherKey: string;
  2680. formMethod?: HTMLFormMethod;
  2681. formEncType?: FormEncType;
  2682. formData?: FormData;
  2683. body?: any;
  2684. }>;
  2685. type InstrumentableRequestHandler = {
  2686. instrument(instrumentations: RequestHandlerInstrumentations): void;
  2687. };
  2688. type RequestHandlerInstrumentations = {
  2689. request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
  2690. };
  2691. type RequestHandlerInstrumentationInfo = Readonly<{
  2692. request: ReadonlyRequest;
  2693. context: ReadonlyContext | undefined;
  2694. }>;
  2695. /**
  2696. * A Router instance manages all navigation and data loading/mutations
  2697. */
  2698. interface Router {
  2699. /**
  2700. * @private
  2701. * PRIVATE - DO NOT USE
  2702. *
  2703. * Return the basename for the router
  2704. */
  2705. get basename(): RouterInit["basename"];
  2706. /**
  2707. * @private
  2708. * PRIVATE - DO NOT USE
  2709. *
  2710. * Return the future config for the router
  2711. */
  2712. get future(): FutureConfig;
  2713. /**
  2714. * @private
  2715. * PRIVATE - DO NOT USE
  2716. *
  2717. * Return the current state of the router
  2718. */
  2719. get state(): RouterState;
  2720. /**
  2721. * @private
  2722. * PRIVATE - DO NOT USE
  2723. *
  2724. * Return the routes for this router instance
  2725. */
  2726. get routes(): AgnosticDataRouteObject[];
  2727. /**
  2728. * @private
  2729. * PRIVATE - DO NOT USE
  2730. *
  2731. * Return the window associated with the router
  2732. */
  2733. get window(): RouterInit["window"];
  2734. /**
  2735. * @private
  2736. * PRIVATE - DO NOT USE
  2737. *
  2738. * Initialize the router, including adding history listeners and kicking off
  2739. * initial data fetches. Returns a function to cleanup listeners and abort
  2740. * any in-progress loads
  2741. */
  2742. initialize(): Router;
  2743. /**
  2744. * @private
  2745. * PRIVATE - DO NOT USE
  2746. *
  2747. * Subscribe to router.state updates
  2748. *
  2749. * @param fn function to call with the new state
  2750. */
  2751. subscribe(fn: RouterSubscriber): () => void;
  2752. /**
  2753. * @private
  2754. * PRIVATE - DO NOT USE
  2755. *
  2756. * Enable scroll restoration behavior in the router
  2757. *
  2758. * @param savedScrollPositions Object that will manage positions, in case
  2759. * it's being restored from sessionStorage
  2760. * @param getScrollPosition Function to get the active Y scroll position
  2761. * @param getKey Function to get the key to use for restoration
  2762. */
  2763. enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
  2764. /**
  2765. * @private
  2766. * PRIVATE - DO NOT USE
  2767. *
  2768. * Navigate forward/backward in the history stack
  2769. * @param to Delta to move in the history stack
  2770. */
  2771. navigate(to: number): Promise<void>;
  2772. /**
  2773. * Navigate to the given path
  2774. * @param to Path to navigate to
  2775. * @param opts Navigation options (method, submission, etc.)
  2776. */
  2777. navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
  2778. /**
  2779. * @private
  2780. * PRIVATE - DO NOT USE
  2781. *
  2782. * Trigger a fetcher load/submission
  2783. *
  2784. * @param key Fetcher key
  2785. * @param routeId Route that owns the fetcher
  2786. * @param href href to fetch
  2787. * @param opts Fetcher options, (method, submission, etc.)
  2788. */
  2789. fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
  2790. /**
  2791. * @private
  2792. * PRIVATE - DO NOT USE
  2793. *
  2794. * Trigger a revalidation of all current route loaders and fetcher loads
  2795. */
  2796. revalidate(): Promise<void>;
  2797. /**
  2798. * @private
  2799. * PRIVATE - DO NOT USE
  2800. *
  2801. * Utility function to create an href for the given location
  2802. * @param location
  2803. */
  2804. createHref(location: Location | URL): string;
  2805. /**
  2806. * @private
  2807. * PRIVATE - DO NOT USE
  2808. *
  2809. * Utility function to URL encode a destination path according to the internal
  2810. * history implementation
  2811. * @param to
  2812. */
  2813. encodeLocation(to: To): Path;
  2814. /**
  2815. * @private
  2816. * PRIVATE - DO NOT USE
  2817. *
  2818. * Get/create a fetcher for the given key
  2819. * @param key
  2820. */
  2821. getFetcher<TData = any>(key: string): Fetcher<TData>;
  2822. /**
  2823. * @internal
  2824. * PRIVATE - DO NOT USE
  2825. *
  2826. * Reset the fetcher for a given key
  2827. * @param key
  2828. */
  2829. resetFetcher(key: string, opts?: {
  2830. reason?: unknown;
  2831. }): void;
  2832. /**
  2833. * @private
  2834. * PRIVATE - DO NOT USE
  2835. *
  2836. * Delete the fetcher for a given key
  2837. * @param key
  2838. */
  2839. deleteFetcher(key: string): void;
  2840. /**
  2841. * @private
  2842. * PRIVATE - DO NOT USE
  2843. *
  2844. * Cleanup listeners and abort any in-progress loads
  2845. */
  2846. dispose(): void;
  2847. /**
  2848. * @private
  2849. * PRIVATE - DO NOT USE
  2850. *
  2851. * Get a navigation blocker
  2852. * @param key The identifier for the blocker
  2853. * @param fn The blocker function implementation
  2854. */
  2855. getBlocker(key: string, fn: BlockerFunction): Blocker;
  2856. /**
  2857. * @private
  2858. * PRIVATE - DO NOT USE
  2859. *
  2860. * Delete a navigation blocker
  2861. * @param key The identifier for the blocker
  2862. */
  2863. deleteBlocker(key: string): void;
  2864. /**
  2865. * @private
  2866. * PRIVATE DO NOT USE
  2867. *
  2868. * Patch additional children routes into an existing parent route
  2869. * @param routeId The parent route id or a callback function accepting `patch`
  2870. * to perform batch patching
  2871. * @param children The additional children routes
  2872. * @param unstable_allowElementMutations Allow mutation or route elements on
  2873. * existing routes. Intended for RSC-usage
  2874. * only.
  2875. */
  2876. patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
  2877. /**
  2878. * @private
  2879. * PRIVATE - DO NOT USE
  2880. *
  2881. * HMR needs to pass in-flight route updates to React Router
  2882. * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
  2883. */
  2884. _internalSetRoutes(routes: AgnosticRouteObject[]): void;
  2885. /**
  2886. * @private
  2887. * PRIVATE - DO NOT USE
  2888. *
  2889. * Cause subscribers to re-render. This is used to force a re-render.
  2890. */
  2891. _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
  2892. /**
  2893. * @private
  2894. * PRIVATE - DO NOT USE
  2895. *
  2896. * Internal fetch AbortControllers accessed by unit tests
  2897. */
  2898. _internalFetchControllers: Map<string, AbortController>;
  2899. }
  2900. /**
  2901. * State maintained internally by the router. During a navigation, all states
  2902. * reflect the "old" location unless otherwise noted.
  2903. */
  2904. interface RouterState {
  2905. /**
  2906. * The action of the most recent navigation
  2907. */
  2908. historyAction: Action;
  2909. /**
  2910. * The current location reflected by the router
  2911. */
  2912. location: Location;
  2913. /**
  2914. * The current set of route matches
  2915. */
  2916. matches: AgnosticDataRouteMatch[];
  2917. /**
  2918. * Tracks whether we've completed our initial data load
  2919. */
  2920. initialized: boolean;
  2921. /**
  2922. * Current scroll position we should start at for a new view
  2923. * - number -> scroll position to restore to
  2924. * - false -> do not restore scroll at all (used during submissions/revalidations)
  2925. * - null -> don't have a saved position, scroll to hash or top of page
  2926. */
  2927. restoreScrollPosition: number | false | null;
  2928. /**
  2929. * Indicate whether this navigation should skip resetting the scroll position
  2930. * if we are unable to restore the scroll position
  2931. */
  2932. preventScrollReset: boolean;
  2933. /**
  2934. * Tracks the state of the current navigation
  2935. */
  2936. navigation: Navigation;
  2937. /**
  2938. * Tracks any in-progress revalidations
  2939. */
  2940. revalidation: RevalidationState;
  2941. /**
  2942. * Data from the loaders for the current matches
  2943. */
  2944. loaderData: RouteData;
  2945. /**
  2946. * Data from the action for the current matches
  2947. */
  2948. actionData: RouteData | null;
  2949. /**
  2950. * Errors caught from loaders for the current matches
  2951. */
  2952. errors: RouteData | null;
  2953. /**
  2954. * Map of current fetchers
  2955. */
  2956. fetchers: Map<string, Fetcher>;
  2957. /**
  2958. * Map of current blockers
  2959. */
  2960. blockers: Map<string, Blocker>;
  2961. }
  2962. /**
  2963. * Data that can be passed into hydrate a Router from SSR
  2964. */
  2965. type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
  2966. /**
  2967. * Future flags to toggle new feature behavior
  2968. */
  2969. interface FutureConfig {
  2970. }
  2971. /**
  2972. * Initialization options for createRouter
  2973. */
  2974. interface RouterInit {
  2975. routes: AgnosticRouteObject[];
  2976. history: History;
  2977. basename?: string;
  2978. getContext?: () => MaybePromise<RouterContextProvider>;
  2979. unstable_instrumentations?: unstable_ClientInstrumentation[];
  2980. mapRouteProperties?: MapRoutePropertiesFunction;
  2981. future?: Partial<FutureConfig>;
  2982. hydrationRouteProperties?: string[];
  2983. hydrationData?: HydrationState;
  2984. window?: Window;
  2985. dataStrategy?: DataStrategyFunction;
  2986. patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
  2987. }
  2988. /**
  2989. * State returned from a server-side query() call
  2990. */
  2991. interface StaticHandlerContext {
  2992. basename: Router["basename"];
  2993. location: RouterState["location"];
  2994. matches: RouterState["matches"];
  2995. loaderData: RouterState["loaderData"];
  2996. actionData: RouterState["actionData"];
  2997. errors: RouterState["errors"];
  2998. statusCode: number;
  2999. loaderHeaders: Record<string, Headers>;
  3000. actionHeaders: Record<string, Headers>;
  3001. _deepestRenderedBoundaryId?: string | null;
  3002. }
  3003. /**
  3004. * A StaticHandler instance manages a singular SSR navigation/fetch event
  3005. */
  3006. interface StaticHandler {
  3007. dataRoutes: AgnosticDataRouteObject[];
  3008. query(request: Request, opts?: {
  3009. requestContext?: unknown;
  3010. filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
  3011. skipLoaderErrorBubbling?: boolean;
  3012. skipRevalidation?: boolean;
  3013. dataStrategy?: DataStrategyFunction<unknown>;
  3014. generateMiddlewareResponse?: (query: (r: Request, args?: {
  3015. filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
  3016. }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
  3017. }): Promise<StaticHandlerContext | Response>;
  3018. queryRoute(request: Request, opts?: {
  3019. routeId?: string;
  3020. requestContext?: unknown;
  3021. dataStrategy?: DataStrategyFunction<unknown>;
  3022. generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
  3023. }): Promise<any>;
  3024. }
  3025. type ViewTransitionOpts = {
  3026. currentLocation: Location;
  3027. nextLocation: Location;
  3028. };
  3029. /**
  3030. * Subscriber function signature for changes to router state
  3031. */
  3032. interface RouterSubscriber {
  3033. (state: RouterState, opts: {
  3034. deletedFetchers: string[];
  3035. newErrors: RouteData | null;
  3036. viewTransitionOpts?: ViewTransitionOpts;
  3037. flushSync: boolean;
  3038. }): void;
  3039. }
  3040. /**
  3041. * Function signature for determining the key to be used in scroll restoration
  3042. * for a given location
  3043. */
  3044. interface GetScrollRestorationKeyFunction {
  3045. (location: Location, matches: UIMatch[]): string | null;
  3046. }
  3047. /**
  3048. * Function signature for determining the current scroll position
  3049. */
  3050. interface GetScrollPositionFunction {
  3051. (): number;
  3052. }
  3053. /**
  3054. * - "route": relative to the route hierarchy so `..` means remove all segments
  3055. * of the current route even if it has many. For example, a `route("posts/:id")`
  3056. * would have both `:id` and `posts` removed from the url.
  3057. * - "path": relative to the pathname so `..` means remove one segment of the
  3058. * pathname. For example, a `route("posts/:id")` would have only `:id` removed
  3059. * from the url.
  3060. */
  3061. type RelativeRoutingType = "route" | "path";
  3062. type BaseNavigateOrFetchOptions = {
  3063. preventScrollReset?: boolean;
  3064. relative?: RelativeRoutingType;
  3065. flushSync?: boolean;
  3066. };
  3067. type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
  3068. replace?: boolean;
  3069. state?: any;
  3070. fromRouteId?: string;
  3071. viewTransition?: boolean;
  3072. };
  3073. type BaseSubmissionOptions = {
  3074. formMethod?: HTMLFormMethod;
  3075. formEncType?: FormEncType;
  3076. } & ({
  3077. formData: FormData;
  3078. body?: undefined;
  3079. } | {
  3080. formData?: undefined;
  3081. body: any;
  3082. });
  3083. /**
  3084. * Options for a navigate() call for a normal (non-submission) navigation
  3085. */
  3086. type LinkNavigateOptions = BaseNavigateOptions;
  3087. /**
  3088. * Options for a navigate() call for a submission navigation
  3089. */
  3090. type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
  3091. /**
  3092. * Options to pass to navigate() for a navigation
  3093. */
  3094. type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
  3095. /**
  3096. * Options for a fetch() load
  3097. */
  3098. type LoadFetchOptions = BaseNavigateOrFetchOptions;
  3099. /**
  3100. * Options for a fetch() submission
  3101. */
  3102. type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
  3103. /**
  3104. * Options to pass to fetch()
  3105. */
  3106. type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
  3107. /**
  3108. * Potential states for state.navigation
  3109. */
  3110. type NavigationStates = {
  3111. Idle: {
  3112. state: "idle";
  3113. location: undefined;
  3114. formMethod: undefined;
  3115. formAction: undefined;
  3116. formEncType: undefined;
  3117. formData: undefined;
  3118. json: undefined;
  3119. text: undefined;
  3120. };
  3121. Loading: {
  3122. state: "loading";
  3123. location: Location;
  3124. formMethod: Submission["formMethod"] | undefined;
  3125. formAction: Submission["formAction"] | undefined;
  3126. formEncType: Submission["formEncType"] | undefined;
  3127. formData: Submission["formData"] | undefined;
  3128. json: Submission["json"] | undefined;
  3129. text: Submission["text"] | undefined;
  3130. };
  3131. Submitting: {
  3132. state: "submitting";
  3133. location: Location;
  3134. formMethod: Submission["formMethod"];
  3135. formAction: Submission["formAction"];
  3136. formEncType: Submission["formEncType"];
  3137. formData: Submission["formData"];
  3138. json: Submission["json"];
  3139. text: Submission["text"];
  3140. };
  3141. };
  3142. type Navigation = NavigationStates[keyof NavigationStates];
  3143. type RevalidationState = "idle" | "loading";
  3144. /**
  3145. * Potential states for fetchers
  3146. */
  3147. type FetcherStates<TData = any> = {
  3148. /**
  3149. * The fetcher is not calling a loader or action
  3150. *
  3151. * ```tsx
  3152. * fetcher.state === "idle"
  3153. * ```
  3154. */
  3155. Idle: {
  3156. state: "idle";
  3157. formMethod: undefined;
  3158. formAction: undefined;
  3159. formEncType: undefined;
  3160. text: undefined;
  3161. formData: undefined;
  3162. json: undefined;
  3163. /**
  3164. * If the fetcher has never been called, this will be undefined.
  3165. */
  3166. data: TData | undefined;
  3167. };
  3168. /**
  3169. * The fetcher is loading data from a {@link LoaderFunction | loader} from a
  3170. * call to {@link FetcherWithComponents.load | `fetcher.load`}.
  3171. *
  3172. * ```tsx
  3173. * // somewhere
  3174. * <button onClick={() => fetcher.load("/some/route") }>Load</button>
  3175. *
  3176. * // the state will update
  3177. * fetcher.state === "loading"
  3178. * ```
  3179. */
  3180. Loading: {
  3181. state: "loading";
  3182. formMethod: Submission["formMethod"] | undefined;
  3183. formAction: Submission["formAction"] | undefined;
  3184. formEncType: Submission["formEncType"] | undefined;
  3185. text: Submission["text"] | undefined;
  3186. formData: Submission["formData"] | undefined;
  3187. json: Submission["json"] | undefined;
  3188. data: TData | undefined;
  3189. };
  3190. /**
  3191. 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`}.
  3192. ```tsx
  3193. // somewhere
  3194. <input
  3195. onChange={e => {
  3196. fetcher.submit(event.currentTarget.form, { method: "post" });
  3197. }}
  3198. />
  3199. // the state will update
  3200. fetcher.state === "submitting"
  3201. // and formData will be available
  3202. fetcher.formData
  3203. ```
  3204. */
  3205. Submitting: {
  3206. state: "submitting";
  3207. formMethod: Submission["formMethod"];
  3208. formAction: Submission["formAction"];
  3209. formEncType: Submission["formEncType"];
  3210. text: Submission["text"];
  3211. formData: Submission["formData"];
  3212. json: Submission["json"];
  3213. data: TData | undefined;
  3214. };
  3215. };
  3216. type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
  3217. interface BlockerBlocked {
  3218. state: "blocked";
  3219. reset: () => void;
  3220. proceed: () => void;
  3221. location: Location;
  3222. }
  3223. interface BlockerUnblocked {
  3224. state: "unblocked";
  3225. reset: undefined;
  3226. proceed: undefined;
  3227. location: undefined;
  3228. }
  3229. interface BlockerProceeding {
  3230. state: "proceeding";
  3231. reset: undefined;
  3232. proceed: undefined;
  3233. location: Location;
  3234. }
  3235. type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
  3236. type BlockerFunction = (args: {
  3237. currentLocation: Location;
  3238. nextLocation: Location;
  3239. historyAction: Action;
  3240. }) => boolean;
  3241. declare const IDLE_NAVIGATION: NavigationStates["Idle"];
  3242. declare const IDLE_FETCHER: FetcherStates["Idle"];
  3243. declare const IDLE_BLOCKER: BlockerUnblocked;
  3244. /**
  3245. * Create a router and listen to history POP navigations
  3246. */
  3247. declare function createRouter(init: RouterInit): Router;
  3248. interface CreateStaticHandlerOptions {
  3249. basename?: string;
  3250. mapRouteProperties?: MapRoutePropertiesFunction;
  3251. unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
  3252. future?: {};
  3253. }
  3254. export { type NonIndexRouteObject as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyResult as D, type Path as E, type Func as F, type GetLoaderData as G, type HeadersFunction as H, type PathPattern as I, type PathMatch as J, type Navigation as K, type Location as L, type MetaFunction as M, type Normalize as N, Action as O, type Params as P, type RouteObject as Q, type RouteModule$1 as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type InitialEntry as V, type HydrationState as W, type IndexRouteObject as X, type RouteComponentType as Y, type HydrateFallbackType as Z, type ErrorBoundaryType as _, type ClientLoaderFunction as a, type RouterProps as a$, type Equal as a0, type RouterState as a1, type PatchRoutesOnNavigationFunction as a2, type DataRouteObject as a3, type StaticHandler as a4, type GetScrollPositionFunction as a5, type GetScrollRestorationKeyFunction as a6, type StaticHandlerContext as a7, type Fetcher as a8, type NavigationStates as a9, type unstable_InstrumentationHandlerResult as aA, IDLE_NAVIGATION as aB, IDLE_FETCHER as aC, IDLE_BLOCKER as aD, data as aE, generatePath as aF, isRouteErrorResponse as aG, matchPath as aH, matchRoutes as aI, redirect as aJ, redirectDocument as aK, replace as aL, resolvePath as aM, type DataRouteMatch as aN, type Navigator as aO, type PatchRoutesOnNavigationFunctionArgs as aP, type RouteMatch as aQ, AwaitContextProvider as aR, type AwaitProps as aS, type IndexRouteProps as aT, type LayoutRouteProps as aU, type MemoryRouterOpts as aV, type MemoryRouterProps as aW, type NavigateProps as aX, type OutletProps as aY, type PathRouteProps as aZ, type RouteProps as a_, type RouterSubscriber as aa, type RouterNavigateOptions as ab, type RouterFetchOptions as ac, type RevalidationState as ad, type ActionFunctionArgs as ae, type DataStrategyFunctionArgs as af, type DataStrategyMatch as ag, DataWithResponseInit as ah, type ErrorResponse as ai, type FormEncType as aj, type FormMethod as ak, type HTMLFormMethod as al, type LazyRouteFunction as am, type LoaderFunctionArgs as an, type MiddlewareFunction as ao, type PathParam as ap, type RedirectFunction as aq, type RouterContext as ar, type ShouldRevalidateFunctionArgs as as, createContext as at, createPath as au, parsePath as av, type unstable_ServerInstrumentation as aw, type unstable_InstrumentRequestHandlerFunction as ax, type unstable_InstrumentRouterFunction as ay, type unstable_InstrumentRouteFunction 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$1 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 RouterProviderProps as f, type unstable_ClientOnErrorFunction as g, type LinkDescriptor as h, type Pretty as i, type MetaDescriptor as j, type ServerDataFunctionArgs as k, type MiddlewareNextFunction as l, type ClientDataFunctionArgs as m, type ServerDataFrom as n, type GetActionData as o, type Router as p, type RouteModules as q, type DataStrategyFunction as r, type MiddlewareEnabled as s, type AppLoadContext as t, type unstable_ClientInstrumentation as u, type NavigateOptions as v, type Blocker as w, type SerializeFrom as x, type RelativeRoutingType as y, type ParamParseKey as z };