vue-router.d.ts 45 KB

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