router-BbqN7H95.d.mts 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. /*!
  2. * vue-router v4.6.3
  3. * (c) 2025 Eduardo San Martin Morote
  4. * @license MIT
  5. */
  6. import { App, Component, ComponentPublicInstance, DefineComponent, Ref, ShallowRef } from "vue";
  7. //#region src/query.d.ts
  8. /**
  9. * Possible values in normalized {@link LocationQuery}. `null` renders the query
  10. * param but without an `=`.
  11. *
  12. * @example
  13. * ```
  14. * ?isNull&isEmpty=&other=other
  15. * gives
  16. * `{ isNull: null, isEmpty: '', other: 'other' }`.
  17. * ```
  18. *
  19. * @internal
  20. */
  21. type LocationQueryValue = string | null;
  22. /**
  23. * Possible values when defining a query. `undefined` allows to remove a value.
  24. *
  25. * @internal
  26. */
  27. type LocationQueryValueRaw = LocationQueryValue | number | undefined;
  28. /**
  29. * Normalized query object that appears in {@link RouteLocationNormalized}
  30. *
  31. * @public
  32. */
  33. type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>;
  34. /**
  35. * Loose {@link LocationQuery} object that can be passed to functions like
  36. * {@link Router.push} and {@link Router.replace} or anywhere when creating a
  37. * {@link RouteLocationRaw}
  38. *
  39. * @public
  40. */
  41. type LocationQueryRaw = Record<string | number, LocationQueryValueRaw | LocationQueryValueRaw[]>;
  42. /**
  43. * Transforms a queryString into a {@link LocationQuery} object. Accept both, a
  44. * version with the leading `?` and without Should work as URLSearchParams
  45. * @internal
  46. *
  47. * @param search - search string to parse
  48. * @returns a query object
  49. */
  50. declare function parseQuery(search: string): LocationQuery;
  51. /**
  52. * Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
  53. * doesn't prepend a `?`
  54. *
  55. * @internal
  56. *
  57. * @param query - query object to stringify
  58. * @returns string version of the query without the leading `?`
  59. */
  60. declare function stringifyQuery(query: LocationQueryRaw | undefined): string;
  61. //#endregion
  62. //#region src/config.d.ts
  63. /**
  64. * Allows customizing existing types of the router that are used globally like `$router`, `<RouterLink>`, etc. **ONLY FOR INTERNAL USAGE**.
  65. *
  66. * - `$router` - the router instance
  67. * - `$route` - the current route location
  68. * - `beforeRouteEnter` - Page component option
  69. * - `beforeRouteUpdate` - Page component option
  70. * - `beforeRouteLeave` - Page component option
  71. * - `RouterLink` - RouterLink Component
  72. * - `RouterView` - RouterView Component
  73. *
  74. * @internal
  75. */
  76. interface TypesConfig {}
  77. //#endregion
  78. //#region src/typed-routes/route-map.d.ts
  79. /**
  80. * Helper type to define a Typed `RouteRecord`
  81. * @see {@link RouteRecord}
  82. */
  83. interface RouteRecordInfo<Name extends string | symbol = string, Path extends string = string, ParamsRaw extends RouteParamsRawGeneric = RouteParamsRawGeneric, Params extends RouteParamsGeneric = RouteParamsGeneric, ChildrenNames extends string | symbol = never> {
  84. name: Name;
  85. path: Path;
  86. paramsRaw: ParamsRaw;
  87. params: Params;
  88. childrenNames: ChildrenNames;
  89. }
  90. type RouteRecordInfoGeneric = RouteRecordInfo<string | symbol, string, RouteParamsRawGeneric, RouteParamsGeneric, string | symbol>;
  91. /**
  92. * Convenience type to get the typed RouteMap or a generic one if not provided. It is extracted from the {@link TypesConfig} if it exists, it becomes {@link RouteMapGeneric} otherwise.
  93. */
  94. type RouteMap = TypesConfig extends Record<'RouteNamedMap', infer RouteNamedMap> ? RouteNamedMap : RouteMapGeneric;
  95. /**
  96. * Generic version of the `RouteMap`.
  97. */
  98. type RouteMapGeneric = Record<string | symbol, RouteRecordInfoGeneric>;
  99. //#endregion
  100. //#region src/types/utils.d.ts
  101. /**
  102. * Creates a union type that still allows autocompletion for strings.
  103. * @internal
  104. */
  105. type _LiteralUnion<LiteralType, BaseType extends string = string> = LiteralType | (BaseType & Record<never, never>);
  106. /**
  107. * Maybe a promise maybe not
  108. * @internal
  109. */
  110. type _Awaitable<T> = T | PromiseLike<T>;
  111. /**
  112. * @internal
  113. */
  114. type Simplify<T> = { [K in keyof T]: T[K] } & {};
  115. //#endregion
  116. //#region src/typed-routes/route-records.d.ts
  117. /**
  118. * @internal
  119. */
  120. type RouteRecordRedirectOption = RouteLocationRaw | ((to: RouteLocation, from: RouteLocationNormalizedLoaded) => RouteLocationRaw);
  121. /**
  122. * Generic version of {@link RouteRecordName}.
  123. */
  124. type RouteRecordNameGeneric = string | symbol | undefined;
  125. /**
  126. * Possible values for a route record **after normalization**
  127. *
  128. * NOTE: since `RouteRecordName` is a type, it evaluates too early and it's often the generic version {@link RouteRecordNameGeneric}. If you need a typed version of all of the names of routes, use {@link RouteMap | `keyof RouteMap`}
  129. */
  130. type RouteRecordName = RouteMapGeneric extends RouteMap ? RouteRecordNameGeneric : keyof RouteMap;
  131. /**
  132. * @internal
  133. */
  134. type _RouteRecordProps<Name extends keyof RouteMap = keyof RouteMap> = boolean | Record<string, any> | ((to: RouteLocationNormalized<Name>) => Record<string, any>);
  135. //#endregion
  136. //#region src/typed-routes/route-location.d.ts
  137. /**
  138. * Generic version of {@link RouteLocation}. It is used when no {@link RouteMap} is provided.
  139. */
  140. interface RouteLocationGeneric extends _RouteLocationBase, RouteLocationOptions {
  141. /**
  142. * Array of {@link RouteRecord} containing components as they were
  143. * passed when adding records. It can also contain redirect records. This
  144. * can't be used directly. **This property is non-enumerable**.
  145. */
  146. matched: RouteRecord[];
  147. }
  148. /**
  149. * Helper to generate a type safe version of the {@link RouteLocation} type.
  150. */
  151. interface RouteLocationTyped<RouteMap extends RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocationGeneric {
  152. name: Extract<Name, string | symbol>;
  153. params: RouteMap[Name]['params'];
  154. }
  155. /**
  156. * List of all possible {@link RouteLocation} indexed by the route name.
  157. * @internal
  158. */
  159. type RouteLocationTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationTyped<RouteMap, N> };
  160. /**
  161. * Generic version of {@link RouteLocationNormalized} that is used when no {@link RouteMap} is provided.
  162. */
  163. interface RouteLocationNormalizedGeneric extends _RouteLocationBase {
  164. name: RouteRecordNameGeneric;
  165. /**
  166. * Array of {@link RouteRecordNormalized}
  167. */
  168. matched: RouteRecordNormalized[];
  169. }
  170. /**
  171. * Helper to generate a type safe version of the {@link RouteLocationNormalized} type.
  172. */
  173. interface RouteLocationNormalizedTyped<RouteMap extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalizedGeneric {
  174. name: Extract<Name, string | symbol>;
  175. params: RouteMap[Name]['params'];
  176. /**
  177. * Array of {@link RouteRecordNormalized}
  178. */
  179. matched: RouteRecordNormalized[];
  180. }
  181. /**
  182. * List of all possible {@link RouteLocationNormalized} indexed by the route name.
  183. * @internal
  184. */
  185. type RouteLocationNormalizedTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N> };
  186. /**
  187. * Generic version of {@link RouteLocationNormalizedLoaded} that is used when no {@link RouteMap} is provided.
  188. */
  189. interface RouteLocationNormalizedLoadedGeneric extends RouteLocationNormalizedGeneric {
  190. /**
  191. * Array of {@link RouteLocationMatched} containing only plain components (any
  192. * lazy-loaded components have been loaded and were replaced inside the
  193. * `components` object) so it can be directly used to display routes. It
  194. * cannot contain redirect records either. **This property is non-enumerable**.
  195. */
  196. matched: RouteLocationMatched[];
  197. }
  198. /**
  199. * Helper to generate a type safe version of the {@link RouteLocationNormalizedLoaded} type.
  200. */
  201. interface RouteLocationNormalizedLoadedTyped<RouteMap extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalizedLoadedGeneric {
  202. name: Extract<Name, string | symbol>;
  203. params: RouteMap[Name]['params'];
  204. }
  205. /**
  206. * List of all possible {@link RouteLocationNormalizedLoaded} indexed by the route name.
  207. * @internal
  208. */
  209. type RouteLocationNormalizedLoadedTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N> };
  210. /**
  211. * Generic version of {@link RouteLocationAsRelative}. It is used when no {@link RouteMap} is provided.
  212. */
  213. interface RouteLocationAsRelativeGeneric extends RouteQueryAndHash, RouteLocationOptions {
  214. name?: RouteRecordNameGeneric;
  215. params?: RouteParamsRawGeneric;
  216. /**
  217. * A relative path to the current location. This property should be removed
  218. */
  219. path?: undefined;
  220. }
  221. /**
  222. * Helper to generate a type safe version of the {@link RouteLocationAsRelative} type.
  223. */
  224. interface RouteLocationAsRelativeTyped<RouteMap extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationAsRelativeGeneric {
  225. name?: Extract<Name, string | symbol>;
  226. params?: RouteMap[Name]['paramsRaw'];
  227. }
  228. /**
  229. * List of all possible {@link RouteLocationAsRelative} indexed by the route name.
  230. * @internal
  231. */
  232. type RouteLocationAsRelativeTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N> };
  233. /**
  234. * Generic version of {@link RouteLocationAsPath}. It is used when no {@link RouteMap} is provided.
  235. */
  236. interface RouteLocationAsPathGeneric extends RouteQueryAndHash, RouteLocationOptions {
  237. /**
  238. * Percentage encoded pathname section of the URL.
  239. */
  240. path: string;
  241. }
  242. /**
  243. * Helper to generate a type safe version of the {@link RouteLocationAsPath} type.
  244. */
  245. interface RouteLocationAsPathTyped<RouteMap extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationAsPathGeneric {
  246. path: _LiteralUnion<RouteMap[Name]['path']>;
  247. }
  248. /**
  249. * List of all possible {@link RouteLocationAsPath} indexed by the route name.
  250. * @internal
  251. */
  252. type RouteLocationAsPathTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N> };
  253. /**
  254. * Helper to generate a type safe version of the {@link RouteLocationAsString} type.
  255. */
  256. type RouteLocationAsStringTyped<RouteMap extends RouteMapGeneric = RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> = RouteMap[Name]['path'];
  257. /**
  258. * List of all possible {@link RouteLocationAsString} indexed by the route name.
  259. * @internal
  260. */
  261. type RouteLocationAsStringTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationAsStringTyped<RouteMap, N> };
  262. /**
  263. * Generic version of {@link RouteLocationResolved}. It is used when no {@link RouteMap} is provided.
  264. */
  265. interface RouteLocationResolvedGeneric extends RouteLocationGeneric {
  266. /**
  267. * Resolved `href` for the route location that will be set on the `<a href="...">`.
  268. */
  269. href: string;
  270. }
  271. /**
  272. * Helper to generate a type safe version of the {@link RouteLocationResolved} type.
  273. */
  274. interface RouteLocationResolvedTyped<RouteMap extends RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocationTyped<RouteMap, Name> {
  275. /**
  276. * Resolved `href` for the route location that will be set on the `<a href="...">`.
  277. */
  278. href: string;
  279. }
  280. /**
  281. * List of all possible {@link RouteLocationResolved} indexed by the route name.
  282. * @internal
  283. */
  284. type RouteLocationResolvedTypedList<RouteMap extends RouteMapGeneric = RouteMapGeneric> = { [N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N> };
  285. /**
  286. * Type safe versions of types that are exposed by vue-router. We have to use a generic check to allow for names to be `undefined` when no `RouteMap` is provided.
  287. */
  288. /**
  289. * {@link RouteLocationRaw} resolved using the matcher
  290. */
  291. type RouteLocation<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationGeneric : RouteLocationTypedList<RouteMap>[Name];
  292. /**
  293. * Similar to {@link RouteLocation} but its
  294. * {@link RouteLocationNormalizedTyped.matched | `matched` property} cannot contain redirect records
  295. */
  296. type RouteLocationNormalized<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationNormalizedGeneric : RouteLocationNormalizedTypedList<RouteMap>[Name];
  297. /**
  298. * Similar to {@link RouteLocationNormalized} but its `components` do not contain any function to lazy load components.
  299. * In other words, it's ready to be rendered by `<RouterView>`.
  300. */
  301. type RouteLocationNormalizedLoaded<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationNormalizedLoadedGeneric : RouteLocationNormalizedLoadedTypedList<RouteMap>[Name];
  302. /**
  303. * Route location relative to the current location. It accepts other properties than `path` like `params`, `query` and
  304. * `hash` to conveniently change them.
  305. */
  306. type RouteLocationAsRelative<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsRelativeGeneric : RouteLocationAsRelativeTypedList<RouteMap>[Name];
  307. /**
  308. * Route location resolved with {@link Router | `router.resolve()`}.
  309. */
  310. type RouteLocationResolved<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationResolvedGeneric : RouteLocationResolvedTypedList<RouteMap>[Name];
  311. /**
  312. * Same as {@link RouteLocationAsPath} but as a string literal.
  313. */
  314. type RouteLocationAsString<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? string : _LiteralUnion<RouteLocationAsStringTypedList<RouteMap>[Name], string>;
  315. /**
  316. * Route location as an object with a `path` property.
  317. */
  318. type RouteLocationAsPath<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsPathGeneric : RouteLocationAsPathTypedList<RouteMap>[Name];
  319. /**
  320. * Route location that can be passed to `router.push()` and other user-facing APIs.
  321. */
  322. type RouteLocationRaw<Name extends keyof RouteMap = keyof RouteMap> = RouteMapGeneric extends RouteMap ? RouteLocationAsString | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric : _LiteralUnion<RouteLocationAsStringTypedList<RouteMap>[Name], string> | RouteLocationAsRelativeTypedList<RouteMap>[Name] | RouteLocationAsPathTypedList<RouteMap>[Name];
  323. //#endregion
  324. //#region src/typed-routes/navigation-guards.d.ts
  325. /**
  326. * Return types for a Navigation Guard. Based on `TypesConfig`
  327. *
  328. * @see {@link TypesConfig}
  329. */
  330. type NavigationGuardReturn = void | Error | boolean | RouteLocationRaw;
  331. /**
  332. * Navigation Guard with a type parameter for `this`.
  333. * @see {@link TypesConfig}
  334. */
  335. interface NavigationGuardWithThis<T> {
  336. (this: T, to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, next: NavigationGuardNext): _Awaitable<NavigationGuardReturn>;
  337. }
  338. /**
  339. * Navigation Guard.
  340. */
  341. interface NavigationGuard {
  342. (to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, next: NavigationGuardNext): _Awaitable<NavigationGuardReturn>;
  343. }
  344. /**
  345. * Navigation hook triggered after a navigation is settled.
  346. */
  347. interface NavigationHookAfter {
  348. (to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, failure?: NavigationFailure | void): unknown;
  349. }
  350. /**
  351. * `next()` callback passed to navigation guards.
  352. */
  353. interface NavigationGuardNext {
  354. (): void;
  355. (error: Error): void;
  356. (location: RouteLocationRaw): void;
  357. (valid: boolean | undefined): void;
  358. (cb: NavigationGuardNextCallback): void;
  359. }
  360. /**
  361. * Callback that can be passed to `next()` in `beforeRouteEnter()` guards.
  362. */
  363. type NavigationGuardNextCallback = (vm: ComponentPublicInstance) => unknown;
  364. //#endregion
  365. //#region src/matcher/types.d.ts
  366. /**
  367. * Normalized version of a {@link RouteRecord | route record}.
  368. */
  369. interface RouteRecordNormalized {
  370. /**
  371. * {@inheritDoc _RouteRecordBase.path}
  372. */
  373. path: _RouteRecordBase['path'];
  374. /**
  375. * {@inheritDoc _RouteRecordBase.redirect}
  376. */
  377. redirect: _RouteRecordBase['redirect'] | undefined;
  378. /**
  379. * {@inheritDoc _RouteRecordBase.name}
  380. */
  381. name: _RouteRecordBase['name'];
  382. /**
  383. * {@inheritDoc RouteRecordMultipleViews.components}
  384. */
  385. components: RouteRecordMultipleViews['components'] | null | undefined;
  386. /**
  387. * Contains the original modules for lazy loaded components.
  388. * @internal
  389. */
  390. mods: Record<string, unknown>;
  391. /**
  392. * Nested route records.
  393. */
  394. children: RouteRecordRaw[];
  395. /**
  396. * {@inheritDoc _RouteRecordBase.meta}
  397. */
  398. meta: Exclude<_RouteRecordBase['meta'], void>;
  399. /**
  400. * {@inheritDoc RouteRecordMultipleViews.props}
  401. */
  402. props: Record<string, _RouteRecordProps>;
  403. /**
  404. * Registered beforeEnter guards
  405. */
  406. beforeEnter: _RouteRecordBase['beforeEnter'];
  407. /**
  408. * Registered leave guards
  409. *
  410. * @internal
  411. */
  412. leaveGuards: Set<NavigationGuard>;
  413. /**
  414. * Registered update guards
  415. *
  416. * @internal
  417. */
  418. updateGuards: Set<NavigationGuard>;
  419. /**
  420. * Registered beforeRouteEnter callbacks passed to `next` or returned in guards
  421. *
  422. * @internal
  423. */
  424. enterCallbacks: Record<string, NavigationGuardNextCallback[]>;
  425. /**
  426. * Mounted route component instances
  427. * Having the instances on the record mean beforeRouteUpdate and
  428. * beforeRouteLeave guards can only be invoked with the latest mounted app
  429. * instance if there are multiple application instances rendering the same
  430. * view, basically duplicating the content on the page, which shouldn't happen
  431. * in practice. It will work if multiple apps are rendering different named
  432. * views.
  433. */
  434. instances: Record<string, ComponentPublicInstance | undefined | null>;
  435. /**
  436. * Defines if this record is the alias of another one. This property is
  437. * `undefined` if the record is the original one.
  438. */
  439. aliasOf: RouteRecordNormalized | undefined;
  440. }
  441. /**
  442. * {@inheritDoc RouteRecordNormalized}
  443. */
  444. type RouteRecord = RouteRecordNormalized;
  445. //#endregion
  446. //#region src/matcher/pathParserRanker.d.ts
  447. type PathParams = Record<string, string | string[]>;
  448. /**
  449. * A param in a url like `/users/:id`
  450. */
  451. interface PathParserParamKey {
  452. name: string;
  453. repeatable: boolean;
  454. optional: boolean;
  455. }
  456. interface PathParser {
  457. /**
  458. * The regexp used to match a url
  459. */
  460. re: RegExp;
  461. /**
  462. * The score of the parser
  463. */
  464. score: Array<number[]>;
  465. /**
  466. * Keys that appeared in the path
  467. */
  468. keys: PathParserParamKey[];
  469. /**
  470. * Parses a url and returns the matched params or null if it doesn't match. An
  471. * optional param that isn't preset will be an empty string. A repeatable
  472. * param will be an array if there is at least one value.
  473. *
  474. * @param path - url to parse
  475. * @returns a Params object, empty if there are no params. `null` if there is
  476. * no match
  477. */
  478. parse(path: string): PathParams | null;
  479. /**
  480. * Creates a string version of the url
  481. *
  482. * @param params - object of params
  483. * @returns a url
  484. */
  485. stringify(params: PathParams): string;
  486. }
  487. /**
  488. * @internal
  489. */
  490. interface _PathParserOptions {
  491. /**
  492. * Makes the RegExp case-sensitive.
  493. *
  494. * @defaultValue `false`
  495. */
  496. sensitive?: boolean;
  497. /**
  498. * Whether to disallow a trailing slash or not.
  499. *
  500. * @defaultValue `false`
  501. */
  502. strict?: boolean;
  503. /**
  504. * Should the RegExp match from the beginning by prepending a `^` to it.
  505. * @internal
  506. *
  507. * @defaultValue `true`
  508. */
  509. start?: boolean;
  510. /**
  511. * Should the RegExp match until the end by appending a `$` to it.
  512. *
  513. * @deprecated this option will alsways be `true` in the future. Open a discussion in vuejs/router if you need this to be `false`
  514. *
  515. * @defaultValue `true`
  516. */
  517. end?: boolean;
  518. }
  519. type PathParserOptions = Pick<_PathParserOptions, 'end' | 'sensitive' | 'strict'>;
  520. //#endregion
  521. //#region src/matcher/pathMatcher.d.ts
  522. interface RouteRecordMatcher extends PathParser {
  523. record: RouteRecord;
  524. parent: RouteRecordMatcher | undefined;
  525. children: RouteRecordMatcher[];
  526. alias: RouteRecordMatcher[];
  527. }
  528. //#endregion
  529. //#region src/matcher/index.d.ts
  530. /**
  531. * Internal RouterMatcher
  532. *
  533. * @internal
  534. */
  535. interface RouterMatcher {
  536. addRoute: (record: RouteRecordRaw, parent?: RouteRecordMatcher) => () => void;
  537. removeRoute(matcher: RouteRecordMatcher): void;
  538. removeRoute(name: NonNullable<RouteRecordNameGeneric>): void;
  539. clearRoutes: () => void;
  540. getRoutes: () => RouteRecordMatcher[];
  541. getRecordMatcher: (name: NonNullable<RouteRecordNameGeneric>) => RouteRecordMatcher | undefined;
  542. /**
  543. * Resolves a location. Gives access to the route record that corresponds to the actual path as well as filling the corresponding params objects
  544. *
  545. * @param location - MatcherLocationRaw to resolve to a url
  546. * @param currentLocation - MatcherLocation of the current location
  547. */
  548. resolve: (location: MatcherLocationRaw, currentLocation: MatcherLocation) => MatcherLocation;
  549. }
  550. /**
  551. * Creates a Router Matcher.
  552. *
  553. * @internal
  554. * @param routes - array of initial routes
  555. * @param globalOptions - global route options
  556. */
  557. declare function createRouterMatcher(routes: Readonly<RouteRecordRaw[]>, globalOptions: PathParserOptions): RouterMatcher;
  558. //#endregion
  559. //#region src/history/common.d.ts
  560. type HistoryLocation = string;
  561. /**
  562. * Allowed variables in HTML5 history state. Note that pushState clones the state
  563. * passed and does not accept everything: e.g.: it doesn't accept symbols, nor
  564. * functions as values. It also ignores Symbols as keys.
  565. *
  566. * @internal
  567. */
  568. type HistoryStateValue = string | number | boolean | null | undefined | HistoryState | HistoryStateArray;
  569. /**
  570. * Allowed HTML history.state
  571. */
  572. interface HistoryState {
  573. [x: number]: HistoryStateValue;
  574. [x: string]: HistoryStateValue;
  575. }
  576. /**
  577. * Allowed arrays for history.state.
  578. *
  579. * @internal
  580. */
  581. interface HistoryStateArray extends Array<HistoryStateValue> {}
  582. declare enum NavigationType {
  583. pop = "pop",
  584. push = "push",
  585. }
  586. declare enum NavigationDirection {
  587. back = "back",
  588. forward = "forward",
  589. unknown = "",
  590. }
  591. interface NavigationInformation {
  592. type: NavigationType;
  593. direction: NavigationDirection;
  594. delta: number;
  595. }
  596. interface NavigationCallback {
  597. (to: HistoryLocation, from: HistoryLocation, information: NavigationInformation): void;
  598. }
  599. /**
  600. * Interface implemented by History implementations that can be passed to the
  601. * router as {@link Router.history}
  602. *
  603. * @alpha
  604. */
  605. interface RouterHistory {
  606. /**
  607. * Base path that is prepended to every url. This allows hosting an SPA at a
  608. * sub-folder of a domain like `example.com/sub-folder` by having a `base` of
  609. * `/sub-folder`
  610. */
  611. readonly base: string;
  612. /**
  613. * Current History location
  614. */
  615. readonly location: HistoryLocation;
  616. /**
  617. * Current History state
  618. */
  619. readonly state: HistoryState;
  620. /**
  621. * Navigates to a location. In the case of an HTML5 History implementation,
  622. * this will call `history.pushState` to effectively change the URL.
  623. *
  624. * @param to - location to push
  625. * @param data - optional {@link HistoryState} to be associated with the
  626. * navigation entry
  627. */
  628. push(to: HistoryLocation, data?: HistoryState): void;
  629. /**
  630. * Same as {@link RouterHistory.push} but performs a `history.replaceState`
  631. * instead of `history.pushState`
  632. *
  633. * @param to - location to set
  634. * @param data - optional {@link HistoryState} to be associated with the
  635. * navigation entry
  636. */
  637. replace(to: HistoryLocation, data?: HistoryState): void;
  638. /**
  639. * Traverses history in a given direction.
  640. *
  641. * @example
  642. * ```js
  643. * myHistory.go(-1) // equivalent to window.history.back()
  644. * myHistory.go(1) // equivalent to window.history.forward()
  645. * ```
  646. *
  647. * @param delta - distance to travel. If delta is \< 0, it will go back,
  648. * if it's \> 0, it will go forward by that amount of entries.
  649. * @param triggerListeners - whether this should trigger listeners attached to
  650. * the history
  651. */
  652. go(delta: number, triggerListeners?: boolean): void;
  653. /**
  654. * Attach a listener to the History implementation that is triggered when the
  655. * navigation is triggered from outside (like the Browser back and forward
  656. * buttons) or when passing `true` to {@link RouterHistory.back} and
  657. * {@link RouterHistory.forward}
  658. *
  659. * @param callback - listener to attach
  660. * @returns a callback to remove the listener
  661. */
  662. listen(callback: NavigationCallback): () => void;
  663. /**
  664. * Generates the corresponding href to be used in an anchor tag.
  665. *
  666. * @param location - history location that should create an href
  667. */
  668. createHref(location: HistoryLocation): string;
  669. /**
  670. * Clears any event listener attached by the history implementation.
  671. */
  672. destroy(): void;
  673. }
  674. //#endregion
  675. //#region src/types/index.d.ts
  676. type Lazy<T> = () => Promise<T>;
  677. /**
  678. * @internal
  679. */
  680. type RouteParamValue = string;
  681. /**
  682. * @internal
  683. */
  684. type RouteParamValueRaw = RouteParamValue | number | null | undefined;
  685. type RouteParamsGeneric = Record<string, RouteParamValue | RouteParamValue[]>;
  686. type RouteParamsRawGeneric = Record<string, RouteParamValueRaw | Exclude<RouteParamValueRaw, null | undefined>[]>;
  687. /**
  688. * @internal
  689. */
  690. interface RouteQueryAndHash {
  691. query?: LocationQueryRaw;
  692. hash?: string;
  693. }
  694. /**
  695. * @internal
  696. */
  697. interface MatcherLocationAsPath {
  698. path: string;
  699. }
  700. /**
  701. * @internal
  702. */
  703. interface MatcherLocationAsName {
  704. name: RouteRecordNameGeneric;
  705. /**
  706. * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
  707. */
  708. path?: undefined;
  709. params?: RouteParamsGeneric;
  710. }
  711. /**
  712. * @internal
  713. */
  714. interface MatcherLocationAsRelative {
  715. /**
  716. * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
  717. */
  718. path?: undefined;
  719. params?: RouteParamsGeneric;
  720. }
  721. /**
  722. * @internal
  723. */
  724. interface LocationAsRelativeRaw {
  725. name?: RouteRecordNameGeneric;
  726. /**
  727. * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
  728. */
  729. path?: undefined;
  730. params?: RouteParamsRawGeneric;
  731. }
  732. /**
  733. * Common options for all navigation methods.
  734. */
  735. interface RouteLocationOptions {
  736. /**
  737. * Replace the entry in the history instead of pushing a new entry
  738. */
  739. replace?: boolean;
  740. /**
  741. * Triggers the navigation even if the location is the same as the current one.
  742. * Note this will also add a new entry to the history unless `replace: true`
  743. * is passed.
  744. */
  745. force?: boolean;
  746. /**
  747. * State to save using the History API. This cannot contain any reactive
  748. * values and some primitives like Symbols are forbidden. More info at
  749. * https://developer.mozilla.org/en-US/docs/Web/API/History/state
  750. */
  751. state?: HistoryState;
  752. }
  753. /**
  754. * Route Location that can infer the necessary params based on the name.
  755. *
  756. * @internal
  757. */
  758. interface RouteLocationNamedRaw extends RouteQueryAndHash, LocationAsRelativeRaw, RouteLocationOptions {}
  759. /**
  760. * Route Location that can infer the possible paths.
  761. *
  762. * @internal
  763. */
  764. interface RouteLocationPathRaw extends RouteQueryAndHash, MatcherLocationAsPath, RouteLocationOptions {}
  765. interface RouteLocationMatched extends RouteRecordNormalized {
  766. components: Record<string, RouteComponent> | null | undefined;
  767. }
  768. /**
  769. * Base properties for a normalized route location.
  770. *
  771. * @internal
  772. */
  773. interface _RouteLocationBase extends Pick<MatcherLocation, 'name' | 'path' | 'params' | 'meta'> {
  774. /**
  775. * The whole location including the `search` and `hash`. This string is
  776. * percentage encoded.
  777. */
  778. fullPath: string;
  779. /**
  780. * Object representation of the `search` property of the current location.
  781. */
  782. query: LocationQuery;
  783. /**
  784. * Hash of the current location. If present, starts with a `#`.
  785. */
  786. hash: string;
  787. /**
  788. * Contains the location we were initially trying to access before ending up
  789. * on the current location.
  790. */
  791. redirectedFrom: RouteLocation | undefined;
  792. }
  793. /**
  794. * Allowed Component in {@link RouteLocationMatched}
  795. */
  796. type RouteComponent = Component | DefineComponent;
  797. /**
  798. * Allowed Component definitions in route records provided by the user
  799. */
  800. type RawRouteComponent = RouteComponent | Lazy<RouteComponent>;
  801. /**
  802. * Internal type for common properties among all kind of {@link RouteRecordRaw}.
  803. */
  804. interface _RouteRecordBase extends PathParserOptions {
  805. /**
  806. * Path of the record. Should start with `/` unless the record is the child of
  807. * another record.
  808. *
  809. * @example `/users/:id` matches `/users/1` as well as `/users/posva`.
  810. */
  811. path: string;
  812. /**
  813. * Where to redirect if the route is directly matched. The redirection happens
  814. * before any navigation guard and triggers a new navigation with the new
  815. * target location.
  816. */
  817. redirect?: RouteRecordRedirectOption;
  818. /**
  819. * Aliases for the record. Allows defining extra paths that will behave like a
  820. * copy of the record. Allows having paths shorthands like `/users/:id` and
  821. * `/u/:id`. All `alias` and `path` values must share the same params.
  822. */
  823. alias?: string | string[];
  824. /**
  825. * Name for the route record. Must be unique.
  826. */
  827. name?: RouteRecordNameGeneric;
  828. /**
  829. * Before Enter guard specific to this record. Note `beforeEnter` has no
  830. * effect if the record has a `redirect` property.
  831. */
  832. beforeEnter?: NavigationGuardWithThis<undefined> | NavigationGuardWithThis<undefined>[];
  833. /**
  834. * Arbitrary data attached to the record.
  835. */
  836. meta?: RouteMeta;
  837. /**
  838. * Array of nested routes.
  839. */
  840. children?: RouteRecordRaw[];
  841. /**
  842. * Allow passing down params as props to the component rendered by `router-view`.
  843. */
  844. props?: _RouteRecordProps | Record<string, _RouteRecordProps>;
  845. }
  846. /**
  847. * Interface to type `meta` fields in route records.
  848. *
  849. * @example
  850. *
  851. * ```ts
  852. * // typings.d.ts or router.ts
  853. * import 'vue-router';
  854. *
  855. * declare module 'vue-router' {
  856. * interface RouteMeta {
  857. * requiresAuth?: boolean
  858. * }
  859. * }
  860. * ```
  861. */
  862. interface RouteMeta extends Record<PropertyKey, unknown> {}
  863. /**
  864. * Route Record defining one single component with the `component` option.
  865. */
  866. interface RouteRecordSingleView extends _RouteRecordBase {
  867. /**
  868. * Component to display when the URL matches this route.
  869. */
  870. component: RawRouteComponent;
  871. components?: never;
  872. children?: never;
  873. redirect?: never;
  874. /**
  875. * Allow passing down params as props to the component rendered by `router-view`.
  876. */
  877. props?: _RouteRecordProps;
  878. }
  879. /**
  880. * Route Record defining one single component with a nested view. Differently
  881. * from {@link RouteRecordSingleView}, this record has children and allows a
  882. * `redirect` option.
  883. */
  884. interface RouteRecordSingleViewWithChildren extends _RouteRecordBase {
  885. /**
  886. * Component to display when the URL matches this route.
  887. */
  888. component?: RawRouteComponent | null | undefined;
  889. components?: never;
  890. children: RouteRecordRaw[];
  891. /**
  892. * Allow passing down params as props to the component rendered by `router-view`.
  893. */
  894. props?: _RouteRecordProps;
  895. }
  896. /**
  897. * Route Record defining multiple named components with the `components` option.
  898. */
  899. interface RouteRecordMultipleViews extends _RouteRecordBase {
  900. /**
  901. * Components to display when the URL matches this route. Allow using named views.
  902. */
  903. components: Record<string, RawRouteComponent>;
  904. component?: never;
  905. children?: never;
  906. redirect?: never;
  907. /**
  908. * Allow passing down params as props to the component rendered by
  909. * `router-view`. Should be an object with the same keys as `components` or a
  910. * boolean to be applied to every component.
  911. */
  912. props?: Record<string, _RouteRecordProps> | boolean;
  913. }
  914. /**
  915. * Route Record defining multiple named components with the `components` option and children.
  916. */
  917. interface RouteRecordMultipleViewsWithChildren extends _RouteRecordBase {
  918. /**
  919. * Components to display when the URL matches this route. Allow using named views.
  920. */
  921. components?: Record<string, RawRouteComponent> | null | undefined;
  922. component?: never;
  923. children: RouteRecordRaw[];
  924. /**
  925. * Allow passing down params as props to the component rendered by
  926. * `router-view`. Should be an object with the same keys as `components` or a
  927. * boolean to be applied to every component.
  928. */
  929. props?: Record<string, _RouteRecordProps> | boolean;
  930. }
  931. /**
  932. * Route Record that defines a redirect. Cannot have `component` or `components`
  933. * as it is never rendered.
  934. */
  935. interface RouteRecordRedirect extends _RouteRecordBase {
  936. redirect: RouteRecordRedirectOption;
  937. component?: never;
  938. components?: never;
  939. props?: never;
  940. }
  941. type RouteRecordRaw = RouteRecordSingleView | RouteRecordSingleViewWithChildren | RouteRecordMultipleViews | RouteRecordMultipleViewsWithChildren | RouteRecordRedirect;
  942. /**
  943. * Route location that can be passed to the matcher.
  944. */
  945. type MatcherLocationRaw = MatcherLocationAsPath | MatcherLocationAsName | MatcherLocationAsRelative;
  946. /**
  947. * Normalized/resolved Route location that returned by the matcher.
  948. */
  949. interface MatcherLocation {
  950. /**
  951. * Name of the matched record
  952. */
  953. name: RouteRecordNameGeneric | null | undefined;
  954. /**
  955. * Percentage encoded pathname section of the URL.
  956. */
  957. path: string;
  958. /**
  959. * Object of decoded params extracted from the `path`.
  960. */
  961. params: RouteParamsGeneric;
  962. /**
  963. * Merged `meta` properties from all the matched route records.
  964. */
  965. meta: RouteMeta;
  966. /**
  967. * Array of {@link RouteRecord} containing components as they were
  968. * passed when adding records. It can also contain redirect records. This
  969. * can't be used directly
  970. */
  971. matched: RouteRecord[];
  972. }
  973. //#endregion
  974. //#region src/errors.d.ts
  975. /**
  976. * Flags so we can combine them when checking for multiple errors. This is the internal version of
  977. * {@link NavigationFailureType}.
  978. *
  979. * @internal
  980. */
  981. declare const enum ErrorTypes {
  982. MATCHER_NOT_FOUND = 1,
  983. NAVIGATION_GUARD_REDIRECT = 2,
  984. NAVIGATION_ABORTED = 4,
  985. NAVIGATION_CANCELLED = 8,
  986. NAVIGATION_DUPLICATED = 16,
  987. }
  988. /**
  989. * Enumeration with all possible types for navigation failures. Can be passed to
  990. * {@link isNavigationFailure} to check for specific failures.
  991. */
  992. declare enum NavigationFailureType {
  993. /**
  994. * An aborted navigation is a navigation that failed because a navigation
  995. * guard returned `false` or called `next(false)`
  996. */
  997. aborted = 4,
  998. /**
  999. * A cancelled navigation is a navigation that failed because a more recent
  1000. * navigation finished started (not necessarily finished).
  1001. */
  1002. cancelled = 8,
  1003. /**
  1004. * A duplicated navigation is a navigation that failed because it was
  1005. * initiated while already being at the exact same location.
  1006. */
  1007. duplicated = 16,
  1008. }
  1009. /**
  1010. * Extended Error that contains extra information regarding a failed navigation.
  1011. */
  1012. interface NavigationFailure extends Error {
  1013. /**
  1014. * Type of the navigation. One of {@link NavigationFailureType}
  1015. */
  1016. type: ErrorTypes.NAVIGATION_CANCELLED | ErrorTypes.NAVIGATION_ABORTED | ErrorTypes.NAVIGATION_DUPLICATED;
  1017. /**
  1018. * Route location we were navigating from
  1019. */
  1020. from: RouteLocationNormalized;
  1021. /**
  1022. * Route location we were navigating to
  1023. */
  1024. to: RouteLocationNormalized;
  1025. }
  1026. /**
  1027. * Internal error used to detect a redirection.
  1028. *
  1029. * @internal
  1030. */
  1031. interface NavigationRedirectError extends Omit<NavigationFailure, 'to' | 'type'> {
  1032. type: ErrorTypes.NAVIGATION_GUARD_REDIRECT;
  1033. to: RouteLocationRaw;
  1034. }
  1035. /**
  1036. * Check if an object is a {@link NavigationFailure}.
  1037. *
  1038. * @param error - possible {@link NavigationFailure}
  1039. * @param type - optional types to check for
  1040. *
  1041. * @example
  1042. * ```js
  1043. * import { isNavigationFailure, NavigationFailureType } from 'vue-router'
  1044. *
  1045. * router.afterEach((to, from, failure) => {
  1046. * // Any kind of navigation failure
  1047. * if (isNavigationFailure(failure)) {
  1048. * // ...
  1049. * }
  1050. * // Only duplicated navigations
  1051. * if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
  1052. * // ...
  1053. * }
  1054. * // Aborted or canceled navigations
  1055. * if (isNavigationFailure(failure, NavigationFailureType.aborted | NavigationFailureType.cancelled )) {
  1056. * // ...
  1057. * }
  1058. * })
  1059. * ```
  1060. */
  1061. declare function isNavigationFailure(error: any, type?: ErrorTypes.NAVIGATION_GUARD_REDIRECT): error is NavigationRedirectError;
  1062. declare function isNavigationFailure(error: any, type?: ErrorTypes | NavigationFailureType): error is NavigationFailure;
  1063. /**
  1064. * Internal type to define an ErrorHandler
  1065. *
  1066. * @param error - error thrown
  1067. * @param to - location we were navigating to when the error happened
  1068. * @param from - location we were navigating from when the error happened
  1069. * @internal
  1070. */
  1071. interface _ErrorListener {
  1072. (error: any, to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded): any;
  1073. }
  1074. //#endregion
  1075. //#region src/scrollBehavior.d.ts
  1076. /**
  1077. * Scroll position similar to
  1078. * {@link https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions | `ScrollToOptions`}.
  1079. * Note that not all browsers support `behavior`.
  1080. */
  1081. type ScrollPositionCoordinates = {
  1082. behavior?: ScrollOptions['behavior'];
  1083. left?: number;
  1084. top?: number;
  1085. };
  1086. /**
  1087. * Internal normalized version of {@link ScrollPositionCoordinates} that always
  1088. * has `left` and `top` coordinates. Must be a type to be assignable to HistoryStateValue.
  1089. *
  1090. * @internal
  1091. */
  1092. type _ScrollPositionNormalized = {
  1093. behavior?: ScrollOptions['behavior'];
  1094. left: number;
  1095. top: number;
  1096. };
  1097. /**
  1098. * Type of the `scrollBehavior` option that can be passed to `createRouter`.
  1099. */
  1100. interface RouterScrollBehavior {
  1101. /**
  1102. * @param to - Route location where we are navigating to
  1103. * @param from - Route location where we are navigating from
  1104. * @param savedPosition - saved position if it exists, `null` otherwise
  1105. */
  1106. (to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, savedPosition: _ScrollPositionNormalized | null): Awaitable<ScrollPosition | false | void>;
  1107. }
  1108. interface ScrollPositionElement extends ScrollToOptions {
  1109. /**
  1110. * A valid CSS selector. Note some characters must be escaped in id selectors (https://mathiasbynens.be/notes/css-escapes).
  1111. * @example
  1112. * Here are a few examples:
  1113. *
  1114. * - `.title`
  1115. * - `.content:first-child`
  1116. * - `#marker`
  1117. * - `#marker\~with\~symbols`
  1118. * - `#marker.with.dot`: selects `class="with dot" id="marker"`, not `id="marker.with.dot"`
  1119. *
  1120. */
  1121. el: string | Element;
  1122. }
  1123. type ScrollPosition = ScrollPositionCoordinates | ScrollPositionElement;
  1124. type Awaitable<T> = T | PromiseLike<T>;
  1125. //#endregion
  1126. //#region src/experimental/route-resolver/matchers/param-parsers/types.d.ts
  1127. /**
  1128. * Defines a parser that can read a param from the url (string-based) and
  1129. * transform it into a more complex type, or vice versa.
  1130. *
  1131. * @see MatcherPattern
  1132. */
  1133. interface ParamParser<TParam = MatcherQueryParamsValue, TUrlParam = MatcherQueryParamsValue, TParamRaw = TParam> {
  1134. get?: (value: NoInfer<TUrlParam>) => TParam;
  1135. set?: (value: TParamRaw) => TUrlParam;
  1136. }
  1137. //#endregion
  1138. //#region src/experimental/route-resolver/matchers/matcher-pattern.d.ts
  1139. /**
  1140. * Base interface for matcher patterns that extract params from a URL.
  1141. *
  1142. * @template TIn - type of the input value to match against the pattern
  1143. * @template TParams - type of the output value after matching
  1144. * @template TParamsRaw - type of the input value to build the input from
  1145. *
  1146. * In the case of the `path`, the `TIn` is a `string`, but in the case of the
  1147. * query, it's the object of query params. `TParamsRaw` allows for a more permissive
  1148. * type when building the value, for example allowing numbers and strings like
  1149. * the old params.
  1150. *
  1151. * @internal this is the base interface for all matcher patterns, it shouldn't
  1152. * be used directly
  1153. */
  1154. interface MatcherPattern<TIn = string, TParams extends MatcherParamsFormatted = MatcherParamsFormatted, TParamsRaw extends MatcherParamsFormatted = TParams> {
  1155. /**
  1156. * Matches a serialized params value against the pattern.
  1157. *
  1158. * @param value - params value to parse
  1159. * @throws {MatchMiss} if the value doesn't match
  1160. * @returns parsed params object
  1161. */
  1162. match(value: TIn): TParams;
  1163. /**
  1164. * Build a serializable value from parsed params. Should apply encoding if the
  1165. * returned value is a string (e.g path and hash should be encoded but query
  1166. * shouldn't).
  1167. *
  1168. * @param value - params value to parse
  1169. * @returns serialized params value
  1170. */
  1171. build(params: TParamsRaw): TIn;
  1172. }
  1173. /**
  1174. * Handles the `path` part of a URL. It can transform a path string into an
  1175. * object of params and vice versa.
  1176. */
  1177. interface MatcherPatternPath<TParams extends MatcherParamsFormatted = MatcherParamsFormatted,
  1178. // | null // | undefined // | void // so it might be a bit more convenient
  1179. TParamsRaw extends MatcherParamsFormatted = TParams> extends MatcherPattern<string, TParams, TParamsRaw> {}
  1180. /**
  1181. * Allows matching a static path.
  1182. *
  1183. * @example
  1184. * ```ts
  1185. * const matcher = new MatcherPatternPathStatic('/team')
  1186. * matcher.match('/team') // {}
  1187. * matcher.match('/team/123') // throws MatchMiss
  1188. * matcher.build() // '/team'
  1189. * ```
  1190. */
  1191. declare class MatcherPatternPathStatic implements MatcherPatternPath<EmptyParams> {
  1192. readonly path: string;
  1193. /**
  1194. * lowercase version of the path to match against.
  1195. * This is used to make the matching case insensitive.
  1196. */
  1197. private pathi;
  1198. constructor(path: string);
  1199. match(path: string): EmptyParams;
  1200. build(): string;
  1201. }
  1202. /**
  1203. * Options for param parsers in {@link MatcherPatternPathDynamic}.
  1204. */
  1205. type MatcherPatternPathDynamic_ParamOptions<TUrlParam extends string | string[] | null = string | string[] | null, TParam = string | string[] | null, TParamRaw = TParam> = readonly [
  1206. /**
  1207. * Param parser to use for this param.
  1208. */
  1209. parser?: ParamParser<TParam, TUrlParam, TParamRaw>,
  1210. /**
  1211. * Is tha param a repeatable param and should be converted to an array
  1212. */
  1213. repeatable?: boolean,
  1214. /**
  1215. * Can this parameter be omitted or empty (for repeatable params, an empty array).
  1216. */
  1217. optional?: boolean];
  1218. /**
  1219. * Helper type to extract the params from the options object.
  1220. *
  1221. * @internal
  1222. */
  1223. type ExtractParamTypeFromOptions<TParamsOptions> = { [K in keyof TParamsOptions]: TParamsOptions[K] extends MatcherPatternPathDynamic_ParamOptions<any, infer TParam, any> ? TParam : never };
  1224. /**
  1225. * Helper type to extract the raw params from the options object.
  1226. *
  1227. * @internal
  1228. */
  1229. type ExtractLocationParamTypeFromOptions<TParamsOptions> = { [K in keyof TParamsOptions]: TParamsOptions[K] extends MatcherPatternPathDynamic_ParamOptions<any, any, infer TParamRaw> ? TParamRaw : never };
  1230. /**
  1231. * Handles the `path` part of a URL with dynamic parameters.
  1232. */
  1233. declare class MatcherPatternPathDynamic<TParamsOptions> implements MatcherPatternPath<ExtractParamTypeFromOptions<TParamsOptions>, ExtractLocationParamTypeFromOptions<TParamsOptions>> {
  1234. readonly re: RegExp;
  1235. readonly params: TParamsOptions & Record<string, MatcherPatternPathDynamic_ParamOptions<any, any>>;
  1236. readonly pathParts: Array<string | number | Array<string | number>>;
  1237. readonly trailingSlash: boolean | null;
  1238. /**
  1239. * Cached keys of the {@link params} object.
  1240. */
  1241. private paramsKeys;
  1242. /**
  1243. * Creates a new dynamic path matcher.
  1244. *
  1245. * @param re - regex to match the path against
  1246. * @param params - object of param parsers as {@link MatcherPatternPathDynamic_ParamOptions}
  1247. * @param pathParts - array of path parts, where strings are static parts, 1 are regular params, and 0 are splat params (not encode slash)
  1248. * @param trailingSlash - whether the path should end with a trailing slash, null means "do not care" (for trailing splat params)
  1249. */
  1250. constructor(re: RegExp, params: TParamsOptions & Record<string, MatcherPatternPathDynamic_ParamOptions<any, any>>, pathParts: Array<string | number | Array<string | number>>, trailingSlash?: boolean | null);
  1251. match(path: string): Simplify<ExtractParamTypeFromOptions<TParamsOptions>>;
  1252. build(params: Simplify<ExtractLocationParamTypeFromOptions<TParamsOptions>>): string;
  1253. }
  1254. /**
  1255. * Handles the `hash` part of a URL. It can transform a hash string into an
  1256. * object of params and vice versa.
  1257. */
  1258. interface MatcherPatternHash<TParams extends MatcherParamsFormatted = MatcherParamsFormatted> extends MatcherPattern<string, TParams> {}
  1259. /**
  1260. * Generic object of params that can be passed to a matcher.
  1261. */
  1262. type MatcherParamsFormatted = Record<string, unknown>;
  1263. /**
  1264. * Empty object in TS.
  1265. */
  1266. type EmptyParams = Record<PropertyKey, never>;
  1267. /**
  1268. * Possible values for query params in a matcher.
  1269. */
  1270. type MatcherQueryParamsValue = string | null | undefined | Array<string | null>;
  1271. type MatcherQueryParams = Record<string, MatcherQueryParamsValue>;
  1272. //#endregion
  1273. //#region src/location.d.ts
  1274. /**
  1275. * Location object returned by {@link `parseURL`}.
  1276. * @internal
  1277. */
  1278. interface LocationNormalized {
  1279. path: string;
  1280. fullPath: string;
  1281. hash: string;
  1282. query: LocationQuery;
  1283. }
  1284. /**
  1285. * Initial route location where the router is. Can be used in navigation guards
  1286. * to differentiate the initial navigation.
  1287. *
  1288. * @example
  1289. * ```js
  1290. * import { START_LOCATION } from 'vue-router'
  1291. *
  1292. * router.beforeEach((to, from) => {
  1293. * if (from === START_LOCATION) {
  1294. * // initial navigation
  1295. * }
  1296. * })
  1297. * ```
  1298. */
  1299. declare const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded;
  1300. //#endregion
  1301. //#region src/experimental/route-resolver/resolver-abstract.d.ts
  1302. /**
  1303. * Allowed types for a matcher name.
  1304. */
  1305. type RecordName = string | symbol;
  1306. /**
  1307. * Manage and resolve routes. Also handles the encoding, decoding, parsing and
  1308. * serialization of params, query, and hash.
  1309. *
  1310. * - `TMatcherRecordRaw` represents the raw record type passed to {@link addMatcher}.
  1311. * - `TMatcherRecord` represents the normalized record type returned by {@link getRoutes}.
  1312. */
  1313. interface EXPERIMENTAL_Resolver_Base<TRecord> {
  1314. /**
  1315. * Resolves an absolute location (like `/path/to/somewhere`).
  1316. *
  1317. * @param absoluteLocation - The absolute location to resolve.
  1318. * @param currentLocation - This value is ignored and should not be passed if the location is absolute.
  1319. */
  1320. resolve(absoluteLocation: `/${string}`, currentLocation?: undefined): ResolverLocationResolved<TRecord>;
  1321. /**
  1322. * Resolves a string location relative to another location. A relative
  1323. * location can be `./same-folder`, `../parent-folder`, `same-folder`, or
  1324. * even `?page=2`.
  1325. */
  1326. resolve(relativeLocation: string, currentLocation: ResolverLocationResolved<TRecord>): ResolverLocationResolved<TRecord>;
  1327. /**
  1328. * Resolves a location by its name. Any required params or query must be
  1329. * passed in the `options` argument.
  1330. */
  1331. resolve(location: ResolverLocationAsNamed, currentLocation?: undefined): ResolverLocationResolved<TRecord>;
  1332. /**
  1333. * Resolves a location by its absolute path (starts with `/`). Any required query must be passed.
  1334. *
  1335. * @param location - The location to resolve.
  1336. */
  1337. resolve(location: ResolverLocationAsPathAbsolute, currentLocation?: undefined): ResolverLocationResolved<TRecord>;
  1338. resolve(location: ResolverLocationAsPathRelative, currentLocation: ResolverLocationResolved<TRecord>): ResolverLocationResolved<TRecord>;
  1339. /**
  1340. * Resolves a location relative to another location. It reuses existing
  1341. * properties in the `currentLocation` like `params`, `query`, and `hash`.
  1342. */
  1343. resolve(relativeLocation: ResolverLocationAsRelative, currentLocation: ResolverLocationResolved<TRecord>): ResolverLocationResolved<TRecord>;
  1344. /**
  1345. * Get a list of all resolver route records.
  1346. */
  1347. getRoutes(): TRecord[];
  1348. /**
  1349. * Get a resolver record by its name.
  1350. * Previously named `getRecordMatcher()`
  1351. */
  1352. getRoute(name: RecordName): TRecord | undefined;
  1353. }
  1354. /**
  1355. * Returned location object by {@link EXPERIMENTAL_Resolver_Base['resolve']}.
  1356. * It contains the resolved name, params, query, hash, and matched records.
  1357. */
  1358. interface ResolverLocationResolved<TMatched> extends LocationNormalized {
  1359. /**
  1360. * Name of the route record. A symbol if no name is provided.
  1361. */
  1362. name: RecordName;
  1363. /**
  1364. * Parsed params. Already decoded and formatted.
  1365. */
  1366. params: MatcherParamsFormatted;
  1367. /**
  1368. * Chain of route records that lead to the matched one. The last record is
  1369. * the the one that matched the location. Each previous record is the parent
  1370. * of the next one.
  1371. */
  1372. matched: TMatched[];
  1373. }
  1374. /**
  1375. * Location object that can be passed to {@link
  1376. * EXPERIMENTAL_Resolver_Base['resolve']} and is recognized as a `name`.
  1377. *
  1378. * @example
  1379. * ```ts
  1380. * resolver.resolve({ name: 'user', params: { id: 123 } })
  1381. * resolver.resolve({ name: 'user-search', params: {}, query: { page: 2 } })
  1382. * ```
  1383. */
  1384. interface ResolverLocationAsNamed {
  1385. name: RecordName;
  1386. params: MatcherParamsFormatted;
  1387. query?: LocationQueryRaw;
  1388. hash?: string;
  1389. /**
  1390. * @deprecated This is ignored when `name` is provided
  1391. */
  1392. path?: undefined;
  1393. }
  1394. /**
  1395. * Location object that can be passed to {@link EXPERIMENTAL_Resolver_Base['resolve']}
  1396. * and is recognized as a relative path.
  1397. *
  1398. * @example
  1399. * ```ts
  1400. * resolver.resolve({ path: './123' }, currentLocation)
  1401. * resolver.resolve({ path: '..' }, currentLocation)
  1402. * ```
  1403. */
  1404. interface ResolverLocationAsPathRelative {
  1405. path: string;
  1406. query?: LocationQueryRaw;
  1407. hash?: string;
  1408. /**
  1409. * @deprecated This is ignored when `path` is provided
  1410. */
  1411. name?: undefined;
  1412. /**
  1413. * @deprecated This is ignored when `path` (instead of `name`) is provided
  1414. */
  1415. params?: undefined;
  1416. }
  1417. /**
  1418. * Location object that can be passed to {@link EXPERIMENTAL_Resolver_Base['resolve']}
  1419. * and is recognized as an absolute path.
  1420. *
  1421. * @example
  1422. * ```ts
  1423. * resolver.resolve({ path: '/team/123' })
  1424. * ```
  1425. */
  1426. interface ResolverLocationAsPathAbsolute extends ResolverLocationAsPathRelative {
  1427. path: `/${string}`;
  1428. }
  1429. /**
  1430. * Relative location object that can be passed to {@link EXPERIMENTAL_Resolver_Base['resolve']}
  1431. * and is recognized as a relative location, copying the `params`, `query`, and
  1432. * `hash` if not provided.
  1433. *
  1434. * @example
  1435. * ```ts
  1436. * resolver.resolve({ params: { id: 123 } }, currentLocation)
  1437. * resolver.resolve({ hash: '#bottom' }, currentLocation)
  1438. * ```
  1439. */
  1440. interface ResolverLocationAsRelative {
  1441. params?: MatcherParamsFormatted;
  1442. query?: LocationQueryRaw;
  1443. hash?: string;
  1444. /**
  1445. * @deprecated This location is relative to the next parameter. This `name` will be ignored.
  1446. */
  1447. name?: undefined;
  1448. /**
  1449. * @deprecated This location is relative to the next parameter. This `path` will be ignored.
  1450. */
  1451. path?: undefined;
  1452. }
  1453. //#endregion
  1454. //#region src/experimental/route-resolver/matchers/param-parsers/booleans.d.ts
  1455. /**
  1456. * Native Param parser for booleans.
  1457. *
  1458. * @internal
  1459. */
  1460. declare const PARAM_PARSER_BOOL: {
  1461. get: (value: NoInfer<MatcherQueryParamsValue>) => boolean | boolean[] | undefined;
  1462. set: (value: boolean | boolean[] | null | undefined) => string | string[] | null | undefined;
  1463. };
  1464. //#endregion
  1465. //#region src/experimental/route-resolver/matchers/param-parsers/integers.d.ts
  1466. /**
  1467. * Native Param parser for integers.
  1468. *
  1469. * @internal
  1470. */
  1471. declare const PARAM_PARSER_INT: {
  1472. get: (value: NoInfer<MatcherQueryParamsValue>) => number | number[] | null;
  1473. set: (value: number | number[] | null) => string | string[] | null;
  1474. };
  1475. //#endregion
  1476. //#region src/experimental/route-resolver/matchers/param-parsers/index.d.ts
  1477. /**
  1478. * Defines a path param parser.
  1479. *
  1480. * @param parser - the parser to define. Will be returned as is.
  1481. *
  1482. * @see {@link defineQueryParamParser}
  1483. * @see {@link defineParamParser}
  1484. */
  1485. /*! #__NO_SIDE_EFFECTS__ */
  1486. declare function definePathParamParser<TParam, TUrlParam extends string | string[] | null, TParamRaw>(parser: Required<ParamParser<TParam, TUrlParam, TParamRaw>>): Required<ParamParser<TParam, TUrlParam, TParamRaw>>;
  1487. /**
  1488. * Defines a query param parser. Note that query params can also be used as
  1489. * path param parsers.
  1490. *
  1491. * @param parser - the parser to define. Will be returned as is.
  1492. *
  1493. * @see {@link definePathParamParser}
  1494. * @see {@link defineParamParser}
  1495. */
  1496. /*! #__NO_SIDE_EFFECTS__ */
  1497. declare function defineQueryParamParser<TParam, TParamRaw = TParam>(parser: Required<ParamParser<TParam, MatcherQueryParamsValue, TParamRaw>>): Required<ParamParser<TParam, MatcherQueryParamsValue, TParamRaw>>;
  1498. /**
  1499. * Alias for {@link defineQueryParamParser}. Implementing a param parser like this
  1500. * works for path, query, and hash params.
  1501. *
  1502. * @see {@link defineQueryParamParser}
  1503. * @see {@link definePathParamParser}
  1504. */
  1505. declare const defineParamParser: typeof defineQueryParamParser;
  1506. //#endregion
  1507. //#region src/experimental/route-resolver/matchers/matcher-pattern-query.d.ts
  1508. /**
  1509. * Handles the `query` part of a URL. It can transform a query object into an
  1510. * object of params and vice versa.
  1511. */
  1512. interface MatcherPatternQuery<TParams extends MatcherParamsFormatted = MatcherParamsFormatted> extends MatcherPattern<MatcherQueryParams, TParams> {}
  1513. /**
  1514. * Matcher for a specific query parameter. It will read and write the parameter
  1515. */
  1516. declare class MatcherPatternQueryParam<T, ParamName extends string> implements MatcherPatternQuery<Record<ParamName, T>> {
  1517. private paramName;
  1518. private queryKey;
  1519. private format;
  1520. private parser;
  1521. private defaultValue?;
  1522. constructor(paramName: ParamName, queryKey: string, format: 'value' | 'array', parser?: ParamParser<T>, defaultValue?: ((() => T) | T) | undefined);
  1523. match(query: MatcherQueryParams): Record<ParamName, T>;
  1524. build(params: Record<ParamName, T>): MatcherQueryParams;
  1525. }
  1526. //#endregion
  1527. //#region src/experimental/route-resolver/resolver-fixed.d.ts
  1528. /**
  1529. * Base interface for a resolver record that can be extended.
  1530. */
  1531. interface EXPERIMENTAL_ResolverRecord_Base {
  1532. /**
  1533. * Name of the matcher. Unique across all matchers. If missing, this record
  1534. * cannot be matched. This is useful for grouping records.
  1535. */
  1536. name?: RecordName;
  1537. /**
  1538. * {@link MatcherPattern} for the path section of the URI.
  1539. */
  1540. path?: MatcherPatternPath;
  1541. /**
  1542. * {@link MatcherPattern} for the query section of the URI.
  1543. */
  1544. query?: MatcherPatternQuery[];
  1545. /**
  1546. * {@link MatcherPattern} for the hash section of the URI.
  1547. */
  1548. hash?: MatcherPatternHash;
  1549. /**
  1550. * Parent record. The parent can be a group or a matchable record.
  1551. * It will be included in the `matched` array of a resolved location.
  1552. */
  1553. parent?: EXPERIMENTAL_ResolverRecord | null;
  1554. }
  1555. /**
  1556. * A group can contain other useful properties like `meta` defined by the router.
  1557. */
  1558. interface EXPERIMENTAL_ResolverRecord_Group extends EXPERIMENTAL_ResolverRecord_Base {
  1559. /**
  1560. * A group route cannot be matched directly and so names are not allowed.
  1561. */
  1562. name?: undefined;
  1563. path?: undefined;
  1564. hash?: undefined;
  1565. }
  1566. /**
  1567. * A matchable record is a record that can be matched by a path, query or hash
  1568. * and will resolve to a location.
  1569. */
  1570. interface EXPERIMENTAL_ResolverRecord_Matchable extends EXPERIMENTAL_ResolverRecord_Base {
  1571. name: RecordName;
  1572. path: MatcherPatternPath;
  1573. }
  1574. /**
  1575. * A record that can be passed to the resolver. It can be extended via the
  1576. * `ExtensionT` type param.
  1577. */
  1578. type EXPERIMENTAL_ResolverRecord<ExtensionT = {}> = (EXPERIMENTAL_ResolverRecord_Matchable & ExtensionT) | (EXPERIMENTAL_ResolverRecord_Group & ExtensionT);
  1579. /**
  1580. * @alias EXPERIMENTAL_Resolver_Base
  1581. */
  1582. interface EXPERIMENTAL_ResolverFixed<TRecord> extends EXPERIMENTAL_Resolver_Base<TRecord> {}
  1583. /**
  1584. * Creates a fixed resolver that must have all records defined at creation
  1585. * time.
  1586. *
  1587. * @template TRecord - extended type of the records
  1588. * @param {TRecord[]} records - Ordered array of records that will be used to resolve routes
  1589. * @returns a resolver that can be passed to the router
  1590. */
  1591. declare function createFixedResolver<TRecord extends EXPERIMENTAL_ResolverRecord_Matchable>(records: TRecord[]): EXPERIMENTAL_ResolverFixed<TRecord>;
  1592. //#endregion
  1593. //#region src/experimental/router.d.ts
  1594. /**
  1595. * Options to initialize a {@link Router} instance.
  1596. */
  1597. interface EXPERIMENTAL_RouterOptions_Base extends PathParserOptions {
  1598. /**
  1599. * History implementation used by the router. Most web applications should use
  1600. * `createWebHistory` but it requires the server to be properly configured.
  1601. * You can also use a _hash_ based history with `createWebHashHistory` that
  1602. * does not require any configuration on the server but isn't handled at all
  1603. * by search engines and does poorly on SEO.
  1604. *
  1605. * @example
  1606. * ```js
  1607. * createRouter({
  1608. * history: createWebHistory(),
  1609. * // other options...
  1610. * })
  1611. * ```
  1612. */
  1613. history: RouterHistory;
  1614. /**
  1615. * Function to control scrolling when navigating between pages. Can return a
  1616. * Promise to delay scrolling.
  1617. *
  1618. * @see {@link RouterScrollBehavior}.
  1619. *
  1620. * @example
  1621. * ```js
  1622. * function scrollBehavior(to, from, savedPosition) {
  1623. * // `to` and `from` are both route locations
  1624. * // `savedPosition` can be null if there isn't one
  1625. * }
  1626. * ```
  1627. */
  1628. scrollBehavior?: RouterScrollBehavior;
  1629. /**
  1630. * Custom implementation to parse a query. See its counterpart,
  1631. * {@link EXPERIMENTAL_RouterOptions_Base.stringifyQuery}.
  1632. *
  1633. * @example
  1634. * Let's say you want to use the [qs package](https://github.com/ljharb/qs)
  1635. * to parse queries, you can provide both `parseQuery` and `stringifyQuery`:
  1636. * ```js
  1637. * import qs from 'qs'
  1638. *
  1639. * createRouter({
  1640. * // other options...
  1641. * parseQuery: qs.parse,
  1642. * stringifyQuery: qs.stringify,
  1643. * })
  1644. * ```
  1645. */
  1646. parseQuery?: typeof parseQuery;
  1647. /**
  1648. * Custom implementation to stringify a query object. Should not prepend a leading `?`.
  1649. * {@link parseQuery} counterpart to handle query parsing.
  1650. */
  1651. stringifyQuery?: typeof stringifyQuery;
  1652. /**
  1653. * Default class applied to active {@link RouterLink}. If none is provided,
  1654. * `router-link-active` will be applied.
  1655. */
  1656. linkActiveClass?: string;
  1657. /**
  1658. * Default class applied to exact active {@link RouterLink}. If none is provided,
  1659. * `router-link-exact-active` will be applied.
  1660. */
  1661. linkExactActiveClass?: string;
  1662. }
  1663. /**
  1664. * Internal type for common properties among all kind of {@link RouteRecordRaw}.
  1665. */
  1666. interface EXPERIMENTAL_RouteRecord_Base extends EXPERIMENTAL_ResolverRecord_Base {
  1667. /**
  1668. * Where to redirect if the route is directly matched. The redirection happens
  1669. * before any navigation guard and triggers a new navigation with the new
  1670. * target location.
  1671. */
  1672. redirect?: RouteRecordRedirectOption;
  1673. /**
  1674. * Aliases for the record. Allows defining extra paths that will behave like a
  1675. * copy of the record. Allows having paths shorthands like `/users/:id` and
  1676. * `/u/:id`. All `alias` and `path` values must share the same params.
  1677. */
  1678. /**
  1679. * Before Enter guard specific to this record. Note `beforeEnter` has no
  1680. * effect if the record has a `redirect` property.
  1681. */
  1682. /**
  1683. * Arbitrary data attached to the record.
  1684. */
  1685. meta?: RouteMeta;
  1686. /**
  1687. * Components to display when the URL matches this route. Allow using named views.
  1688. */
  1689. components?: Record<string, RawRouteComponent>;
  1690. /**
  1691. * Parent of this component if any
  1692. */
  1693. parent?: EXPERIMENTAL_RouteRecordRaw;
  1694. }
  1695. interface EXPERIMENTAL_RouteRecord_Matchable extends Omit<EXPERIMENTAL_RouteRecord_Base, 'name' | 'path' | 'parent'>, EXPERIMENTAL_ResolverRecord_Matchable {
  1696. components: Record<string, RawRouteComponent>;
  1697. parent?: EXPERIMENTAL_RouteRecordNormalized | null;
  1698. }
  1699. interface EXPERIMENTAL_RouteRecord_Group extends Omit<EXPERIMENTAL_RouteRecord_Base, 'name' | 'path' | 'query' | 'hash' | 'parent'>, EXPERIMENTAL_ResolverRecord_Group {
  1700. components?: Record<string, RawRouteComponent>;
  1701. parent?: EXPERIMENTAL_RouteRecordNormalized | null;
  1702. }
  1703. type EXPERIMENTAL_RouteRecordRaw = EXPERIMENTAL_RouteRecord_Matchable | EXPERIMENTAL_RouteRecord_Group;
  1704. interface EXPERIMENTAL_RouteRecordNormalized_Base {
  1705. /**
  1706. * Contains the original modules for lazy loaded components.
  1707. *
  1708. * @internal
  1709. */
  1710. mods: Record<string, unknown>;
  1711. props: Record<string, _RouteRecordProps>;
  1712. /**
  1713. * Registered leave guards
  1714. *
  1715. * @internal
  1716. */
  1717. leaveGuards: Set<NavigationGuard>;
  1718. /**
  1719. * Registered update guards
  1720. *
  1721. * @internal
  1722. */
  1723. updateGuards: Set<NavigationGuard>;
  1724. instances: Record<string, unknown>;
  1725. }
  1726. interface EXPERIMENTAL_RouteRecordNormalized_Group extends EXPERIMENTAL_RouteRecordNormalized_Base, EXPERIMENTAL_RouteRecord_Group {
  1727. meta: RouteMeta;
  1728. parent: EXPERIMENTAL_RouteRecordNormalized | null;
  1729. }
  1730. interface EXPERIMENTAL_RouteRecordNormalized_Matchable extends EXPERIMENTAL_RouteRecordNormalized_Base, EXPERIMENTAL_RouteRecord_Matchable {
  1731. meta: RouteMeta;
  1732. parent: EXPERIMENTAL_RouteRecordNormalized | null;
  1733. components: Record<string, RawRouteComponent>;
  1734. }
  1735. type EXPERIMENTAL_RouteRecordNormalized = EXPERIMENTAL_RouteRecordNormalized_Matchable | EXPERIMENTAL_RouteRecordNormalized_Group;
  1736. declare function normalizeRouteRecord(record: EXPERIMENTAL_RouteRecord_Group): EXPERIMENTAL_RouteRecordNormalized_Group;
  1737. declare function normalizeRouteRecord(record: EXPERIMENTAL_RouteRecord_Matchable): EXPERIMENTAL_RouteRecordNormalized_Matchable;
  1738. /**
  1739. * Merges route record objects for the experimental resolver format.
  1740. * This function is specifically designed to work with objects that will be passed to normalizeRouteRecord().
  1741. *
  1742. * @internal
  1743. *
  1744. * @param main - main route record object
  1745. * @param routeRecords - route records to merge (from definePage imports)
  1746. * @returns merged route record object
  1747. */
  1748. declare function mergeRouteRecord(main: EXPERIMENTAL_RouteRecordNormalized, ...routeRecords: Partial<EXPERIMENTAL_RouteRecordNormalized>[]): EXPERIMENTAL_RouteRecordNormalized;
  1749. /**
  1750. * Options to initialize an experimental {@link EXPERIMENTAL_Router} instance.
  1751. * @experimental
  1752. */
  1753. interface EXPERIMENTAL_RouterOptions extends EXPERIMENTAL_RouterOptions_Base {
  1754. /**
  1755. * Matcher to use to resolve routes.
  1756. *
  1757. * @experimental
  1758. */
  1759. resolver: EXPERIMENTAL_ResolverFixed<EXPERIMENTAL_RouteRecordNormalized_Matchable>;
  1760. }
  1761. /**
  1762. * Router base instance.
  1763. *
  1764. * @experimental This version is not stable, it's meant to replace {@link Router} in the future.
  1765. */
  1766. interface EXPERIMENTAL_Router_Base<TRecord> {
  1767. /**
  1768. * Current {@link RouteLocationNormalized}
  1769. */
  1770. readonly currentRoute: ShallowRef<RouteLocationNormalizedLoaded>;
  1771. /**
  1772. * Allows turning off the listening of history events. This is a low level api for micro-frontend.
  1773. */
  1774. listening: boolean;
  1775. /**
  1776. * Checks if a route with a given name exists
  1777. *
  1778. * @param name - Name of the route to check
  1779. */
  1780. hasRoute(name: NonNullable<RouteRecordNameGeneric>): boolean;
  1781. /**
  1782. * Get a full list of all the {@link RouteRecord | route records}.
  1783. */
  1784. getRoutes(): TRecord[];
  1785. /**
  1786. * Returns the {@link RouteLocation | normalized version} of a
  1787. * {@link RouteLocationRaw | route location}. Also includes an `href` property
  1788. * that includes any existing `base`. By default, the `currentLocation` used is
  1789. * `router.currentRoute` and should only be overridden in advanced use cases.
  1790. *
  1791. * @param to - Raw route location to resolve
  1792. * @param currentLocation - Optional current location to resolve against
  1793. */
  1794. resolve<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsRelativeTyped<RouteMap, Name>, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolved<Name>;
  1795. resolve(to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolved;
  1796. /**
  1797. * Programmatically navigate to a new URL by pushing an entry in the history
  1798. * stack.
  1799. *
  1800. * @param to - Route location to navigate to
  1801. */
  1802. push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
  1803. /**
  1804. * Programmatically navigate to a new URL by replacing the current entry in
  1805. * the history stack.
  1806. *
  1807. * @param to - Route location to navigate to
  1808. */
  1809. replace(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
  1810. /**
  1811. * Go back in history if possible by calling `history.back()`. Equivalent to
  1812. * `router.go(-1)`.
  1813. */
  1814. back(): void;
  1815. /**
  1816. * Go forward in history if possible by calling `history.forward()`.
  1817. * Equivalent to `router.go(1)`.
  1818. */
  1819. forward(): void;
  1820. /**
  1821. * Allows you to move forward or backward through the history. Calls
  1822. * `history.go()`.
  1823. *
  1824. * @param delta - The position in the history to which you want to move,
  1825. * relative to the current page
  1826. */
  1827. go(delta: number): void;
  1828. /**
  1829. * Add a navigation guard that executes before any navigation. Returns a
  1830. * function that removes the registered guard.
  1831. *
  1832. * @param guard - navigation guard to add
  1833. */
  1834. beforeEach(guard: NavigationGuardWithThis<undefined>): () => void;
  1835. /**
  1836. * Add a navigation guard that executes before navigation is about to be
  1837. * resolved. At this state all component have been fetched and other
  1838. * navigation guards have been successful. Returns a function that removes the
  1839. * registered guard.
  1840. *
  1841. * @param guard - navigation guard to add
  1842. * @returns a function that removes the registered guard
  1843. *
  1844. * @example
  1845. * ```js
  1846. * router.beforeResolve(to => {
  1847. * if (to.meta.requiresAuth && !isAuthenticated) return false
  1848. * })
  1849. * ```
  1850. *
  1851. */
  1852. beforeResolve(guard: NavigationGuardWithThis<undefined>): () => void;
  1853. /**
  1854. * Add a navigation hook that is executed after every navigation. Returns a
  1855. * function that removes the registered hook.
  1856. *
  1857. * @param guard - navigation hook to add
  1858. * @returns a function that removes the registered hook
  1859. *
  1860. * @example
  1861. * ```js
  1862. * router.afterEach((to, from, failure) => {
  1863. * if (isNavigationFailure(failure)) {
  1864. * console.log('failed navigation', failure)
  1865. * }
  1866. * })
  1867. * ```
  1868. */
  1869. afterEach(guard: NavigationHookAfter): () => void;
  1870. /**
  1871. * Adds an error handler that is called every time a non caught error happens
  1872. * during navigation. This includes errors thrown synchronously and
  1873. * asynchronously, errors returned or passed to `next` in any navigation
  1874. * guard, and errors occurred when trying to resolve an async component that
  1875. * is required to render a route.
  1876. *
  1877. * @param handler - error handler to register
  1878. */
  1879. onError(handler: _ErrorListener): () => void;
  1880. /**
  1881. * Returns a Promise that resolves when the router has completed the initial
  1882. * navigation, which means it has resolved all async enter hooks and async
  1883. * components that are associated with the initial route. If the initial
  1884. * navigation already happened, the promise resolves immediately.
  1885. *
  1886. * This is useful in server-side rendering to ensure consistent output on both
  1887. * the server and the client. Note that on server side, you need to manually
  1888. * push the initial location while on client side, the router automatically
  1889. * picks it up from the URL.
  1890. */
  1891. isReady(): Promise<void>;
  1892. /**
  1893. * Called automatically by `app.use(router)`. Should not be called manually by
  1894. * the user. This will trigger the initial navigation when on client side.
  1895. *
  1896. * @internal
  1897. * @param app - Application that uses the router
  1898. */
  1899. install(app: App): void;
  1900. }
  1901. interface EXPERIMENTAL_Router extends EXPERIMENTAL_Router_Base<EXPERIMENTAL_RouteRecordNormalized_Matchable> {
  1902. /**
  1903. * Original options object passed to create the Router
  1904. */
  1905. readonly options: EXPERIMENTAL_RouterOptions;
  1906. /**
  1907. * Dev only method to replace the resolver used by the router. Used during HMR
  1908. *
  1909. * @param newResolver - new resolver to use
  1910. *
  1911. * @internal
  1912. */
  1913. _hmrReplaceResolver?: (newResolver: EXPERIMENTAL_ResolverFixed<EXPERIMENTAL_RouteRecordNormalized_Matchable>) => void;
  1914. }
  1915. /**
  1916. * Creates an experimental Router that allows passing a resolver instead of a
  1917. * routes array. This router does not have `addRoute()` and `removeRoute()`
  1918. * methods and is meant to be used with unplugin-vue-router by generating the
  1919. * resolver from the `pages/` folder
  1920. *
  1921. * @param options - Options to initialize the router
  1922. */
  1923. declare function experimental_createRouter(options: EXPERIMENTAL_RouterOptions): EXPERIMENTAL_Router;
  1924. //#endregion
  1925. export { EXPERIMENTAL_RouteRecordNormalized, EXPERIMENTAL_RouteRecordNormalized_Group, EXPERIMENTAL_RouteRecordNormalized_Matchable, EXPERIMENTAL_RouteRecordRaw, EXPERIMENTAL_RouteRecord_Base, EXPERIMENTAL_RouteRecord_Group, EXPERIMENTAL_RouteRecord_Matchable, EXPERIMENTAL_Router, EXPERIMENTAL_RouterOptions, EXPERIMENTAL_RouterOptions_Base, EXPERIMENTAL_Router_Base, EmptyParams, ErrorTypes, HistoryState, LocationAsRelativeRaw, LocationQuery, LocationQueryRaw, LocationQueryValue, LocationQueryValueRaw, MatcherLocation, MatcherLocationAsPath, MatcherParamsFormatted, MatcherPattern, MatcherPatternHash, MatcherPatternPath, MatcherPatternPathDynamic, MatcherPatternPathDynamic_ParamOptions, MatcherPatternPathStatic, MatcherPatternQuery, MatcherPatternQueryParam, MatcherQueryParams, MatcherQueryParamsValue, NavigationFailure, NavigationFailureType, NavigationGuard, NavigationGuardNext, NavigationGuardNextCallback, NavigationGuardReturn, NavigationGuardWithThis, NavigationHookAfter, NavigationRedirectError, PARAM_PARSER_BOOL, PARAM_PARSER_INT, type ParamParser, type PathParserOptions, RouteComponent, RouteLocation, RouteLocationAsPath, RouteLocationAsPathGeneric, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelative, RouteLocationAsRelativeGeneric, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationAsStringTyped, RouteLocationAsStringTypedList, RouteLocationGeneric, RouteLocationMatched, RouteLocationNamedRaw, RouteLocationNormalized, RouteLocationNormalizedGeneric, RouteLocationNormalizedLoaded, RouteLocationNormalizedLoadedGeneric, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationOptions, RouteLocationPathRaw, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteMap, RouteMapGeneric, RouteMeta, RouteParamValue, RouteParamValueRaw, RouteParamsGeneric, RouteParamsRawGeneric, RouteQueryAndHash, RouteRecord, RouteRecordInfo, RouteRecordInfoGeneric, RouteRecordMultipleViews, RouteRecordMultipleViewsWithChildren, RouteRecordName, RouteRecordNameGeneric, RouteRecordNormalized, RouteRecordRaw, RouteRecordRedirect, RouteRecordRedirectOption, RouteRecordSingleView, RouteRecordSingleViewWithChildren, RouterHistory, RouterMatcher, RouterScrollBehavior, START_LOCATION_NORMALIZED, TypesConfig, _Awaitable, type _PathParserOptions, _RouteLocationBase, _RouteRecordBase, _RouteRecordProps, createFixedResolver, createRouterMatcher, defineParamParser, definePathParamParser, defineQueryParamParser, experimental_createRouter, isNavigationFailure, mergeRouteRecord, normalizeRouteRecord, parseQuery, stringifyQuery };