vue-router.d.ts 61 KB

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