vue-router.d.mts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*!
  2. * vue-router v4.6.4
  3. * (c) 2025 Eduardo San Martin Morote
  4. * @license MIT
  5. */
  6. import { $ as RouteParamsRawGeneric, $t as RouteRecordRedirectOption, At as RouteLocationAsRelativeTyped, B as isNavigationFailure, Bt as RouteLocationNormalizedLoadedTyped, C as START_LOCATION_NORMALIZED, Ct as RouteLocation, Dt as RouteLocationAsPathTypedList, Et as RouteLocationAsPathTyped, F as RouterScrollBehavior, Ft as RouteLocationGeneric, G as RouteLocationMatched, Gt as RouteLocationResolved, H as MatcherLocation, Ht as RouteLocationNormalizedTyped, I as ErrorTypes, It as RouteLocationNormalized, J as RouteLocationPathRaw, Jt as RouteLocationResolvedTypedList, K as RouteLocationNamedRaw, Kt as RouteLocationResolvedGeneric, L as NavigationFailure, Lt as RouteLocationNormalizedGeneric, Mt as RouteLocationAsString, Nt as RouteLocationAsStringTyped, Ot as RouteLocationAsRelative, Pt as RouteLocationAsStringTypedList, Q as RouteParamsGeneric, Qt as RouteRecordNameGeneric, R as NavigationFailureType, Rt as RouteLocationNormalizedLoaded, St as NavigationHookAfter, Tt as RouteLocationAsPathGeneric, U as MatcherLocationAsPath, Ut as RouteLocationNormalizedTypedList, V as LocationAsRelativeRaw, Vt as RouteLocationNormalizedLoadedTypedList, W as RouteComponent, Wt as RouteLocationRaw, X as RouteParamValue, Xt as RouteLocationTypedList, Y as RouteMeta, Yt as RouteLocationTyped, Z as RouteParamValueRaw, Zt as RouteRecordName, _n as parseQuery, _t as NavigationGuard, an as ParamValueZeroOrOne, at as RouteRecordSingleView, bt as NavigationGuardReturn, cn as RouteMap, ct as _RouteRecordBase, d as EXPERIMENTAL_Router_Base, dn as RouteRecordInfoGeneric, dt as RouterMatcher, en as _RouteRecordProps, et as RouteQueryAndHash, fn as TypesConfig, ft as createRouterMatcher, gn as LocationQueryValueRaw, gt as RouteRecordNormalized, hn as LocationQueryValue, ht as RouteRecord, in as ParamValueZeroOrMore, it as RouteRecordRedirect, jt as RouteLocationAsRelativeTypedList, kt as RouteLocationAsRelativeGeneric, ln as RouteMapGeneric, lt as HistoryState, mn as LocationQueryRaw, mt as _PathParserOptions, nn as ParamValue, nt as RouteRecordMultipleViewsWithChildren, on as RouteParams, ot as RouteRecordSingleViewWithChildren, pn as LocationQuery, pt as PathParserOptions, q as RouteLocationOptions, qt as RouteLocationResolvedTyped, rn as ParamValueOneOrMore, rt as RouteRecordRaw, sn as RouteParamsRaw, st as _RouteLocationBase, tn as _Awaitable, tt as RouteRecordMultipleViews, u as EXPERIMENTAL_RouterOptions_Base, un as RouteRecordInfo, ut as RouterHistory, vn as stringifyQuery, vt as NavigationGuardNext, wt as RouteLocationAsPath, xt as NavigationGuardWithThis, yt as NavigationGuardNextCallback, z as NavigationRedirectError, zt as RouteLocationNormalizedLoadedGeneric } from "./router-CWoNjPRp.mjs";
  7. import { AllowedComponentProps, AnchorHTMLAttributes, ComponentCustomProps, ComputedRef, DefineComponent, InjectionKey, MaybeRef, Ref, UnwrapRef, VNode, VNodeProps } from "vue";
  8. //#region src/history/html5.d.ts
  9. /**
  10. * Creates an HTML5 history. Most common history for single page applications.
  11. *
  12. * @param base -
  13. */
  14. declare function createWebHistory(base?: string): RouterHistory;
  15. //#endregion
  16. //#region src/history/memory.d.ts
  17. /**
  18. * 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.
  19. * It's up to the user to replace that location with the starter location by either calling `router.push` or `router.replace`.
  20. *
  21. * @param base - Base applied to all urls, defaults to '/'
  22. * @returns a history object that can be passed to the router constructor
  23. */
  24. declare function createMemoryHistory(base?: string): RouterHistory;
  25. //#endregion
  26. //#region src/history/hash.d.ts
  27. /**
  28. * Creates a hash history. Useful for web applications with no host (e.g. `file://`) or when configuring a server to
  29. * handle any URL is not possible.
  30. *
  31. * @param base - optional base to provide. Defaults to `location.pathname + location.search` If there is a `<base>` tag
  32. * in the `head`, its value will be ignored in favor of this parameter **but note it affects all the history.pushState()
  33. * calls**, meaning that if you use a `<base>` tag, it's `href` value **has to match this parameter** (ignoring anything
  34. * after the `#`).
  35. *
  36. * @example
  37. * ```js
  38. * // at https://example.com/folder
  39. * createWebHashHistory() // gives a url of `https://example.com/folder#`
  40. * createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
  41. * // if the `#` is provided in the base, it won't be added by `createWebHashHistory`
  42. * createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
  43. * // you should avoid doing this because it changes the original url and breaks copying urls
  44. * createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
  45. *
  46. * // at file:///usr/etc/folder/index.html
  47. * // for locations with no `host`, the base is ignored
  48. * createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
  49. * ```
  50. */
  51. declare function createWebHashHistory(base?: string): RouterHistory;
  52. //#endregion
  53. //#region src/router.d.ts
  54. /**
  55. * Options to initialize a {@link Router} instance.
  56. */
  57. interface RouterOptions extends EXPERIMENTAL_RouterOptions_Base {
  58. /**
  59. * Initial list of routes that should be added to the router.
  60. */
  61. routes: Readonly<RouteRecordRaw[]>;
  62. }
  63. /**
  64. * Router instance.
  65. */
  66. interface Router extends EXPERIMENTAL_Router_Base<RouteRecordNormalized> {
  67. /**
  68. * Original options object passed to create the Router
  69. */
  70. readonly options: RouterOptions;
  71. /**
  72. * Add a new {@link RouteRecordRaw | route record} as the child of an existing route.
  73. *
  74. * @param parentName - Parent Route Record where `route` should be appended at
  75. * @param route - Route Record to add
  76. */
  77. addRoute(parentName: NonNullable<RouteRecordNameGeneric>, route: RouteRecordRaw): () => void;
  78. /**
  79. * Add a new {@link RouteRecordRaw | route record} to the router.
  80. *
  81. * @param route - Route Record to add
  82. */
  83. addRoute(route: RouteRecordRaw): () => void;
  84. /**
  85. * Remove an existing route by its name.
  86. *
  87. * @param name - Name of the route to remove
  88. */
  89. removeRoute(name: NonNullable<RouteRecordNameGeneric>): void;
  90. /**
  91. * Delete all routes from the router.
  92. */
  93. clearRoutes(): void;
  94. }
  95. /**
  96. * Creates a Router instance that can be used by a Vue app.
  97. *
  98. * @param options - {@link RouterOptions}
  99. */
  100. declare function createRouter(options: RouterOptions): Router;
  101. //#endregion
  102. //#region src/injectionSymbols.d.ts
  103. /**
  104. * RouteRecord being rendered by the closest ancestor Router View. Used for
  105. * `onBeforeRouteUpdate` and `onBeforeRouteLeave`. rvlm stands for Router View
  106. * Location Matched
  107. *
  108. * @internal
  109. */
  110. declare const matchedRouteKey: InjectionKey<ComputedRef<RouteRecordNormalized | undefined>>;
  111. /**
  112. * Allows overriding the router view depth to control which component in
  113. * `matched` is rendered. rvd stands for Router View Depth
  114. *
  115. * @internal
  116. */
  117. declare const viewDepthKey: InjectionKey<Ref<number> | number>;
  118. /**
  119. * Allows overriding the router instance returned by `useRouter` in tests. r
  120. * stands for router
  121. *
  122. * @internal
  123. */
  124. declare const routerKey: InjectionKey<Router>;
  125. /**
  126. * Allows overriding the current route returned by `useRoute` in tests. rl
  127. * stands for route location
  128. *
  129. * @internal
  130. */
  131. declare const routeLocationKey: InjectionKey<RouteLocationNormalizedLoaded>;
  132. /**
  133. * Allows overriding the current route used by router-view. Internally this is
  134. * used when the `route` prop is passed.
  135. *
  136. * @internal
  137. */
  138. declare const routerViewLocationKey: InjectionKey<Ref<RouteLocationNormalizedLoaded>>;
  139. //#endregion
  140. //#region src/navigationGuards.d.ts
  141. /**
  142. * Add a navigation guard that triggers whenever the component for the current
  143. * location is about to be left. Similar to {@link beforeRouteLeave} but can be
  144. * used in any component. The guard is removed when the component is unmounted.
  145. *
  146. * @param leaveGuard - {@link NavigationGuard}
  147. */
  148. declare function onBeforeRouteLeave(leaveGuard: NavigationGuard): void;
  149. /**
  150. * Add a navigation guard that triggers whenever the current location is about
  151. * to be updated. Similar to {@link beforeRouteUpdate} but can be used in any
  152. * component. The guard is removed when the component is unmounted.
  153. *
  154. * @param updateGuard - {@link NavigationGuard}
  155. */
  156. declare function onBeforeRouteUpdate(updateGuard: NavigationGuard): void;
  157. /**
  158. * Ensures a route is loaded, so it can be passed as o prop to `<RouterView>`.
  159. *
  160. * @param route - resolved route to load
  161. */
  162. declare function loadRouteLocation(route: RouteLocation | RouteLocationNormalized): Promise<RouteLocationNormalizedLoaded>;
  163. //#endregion
  164. //#region src/RouterLink.d.ts
  165. interface RouterLinkOptions {
  166. /**
  167. * Route Location the link should navigate to when clicked on.
  168. */
  169. to: RouteLocationRaw;
  170. /**
  171. * Calls `router.replace` instead of `router.push`.
  172. */
  173. replace?: boolean;
  174. }
  175. interface RouterLinkProps extends RouterLinkOptions {
  176. /**
  177. * Whether RouterLink should not wrap its content in an `a` tag. Useful when
  178. * using `v-slot` to create a custom RouterLink
  179. */
  180. custom?: boolean;
  181. /**
  182. * Class to apply when the link is active
  183. */
  184. activeClass?: string;
  185. /**
  186. * Class to apply when the link is exact active
  187. */
  188. exactActiveClass?: string;
  189. /**
  190. * Value passed to the attribute `aria-current` when the link is exact active.
  191. *
  192. * @defaultValue `'page'`
  193. */
  194. ariaCurrentValue?: 'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false';
  195. /**
  196. * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
  197. */
  198. viewTransition?: boolean;
  199. }
  200. /**
  201. * Options passed to {@link useLink}.
  202. */
  203. interface UseLinkOptions<Name extends keyof RouteMap = keyof RouteMap> {
  204. to: MaybeRef<RouteLocationAsString | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPath | RouteLocationRaw>;
  205. replace?: MaybeRef<boolean | undefined>;
  206. /**
  207. * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
  208. */
  209. viewTransition?: boolean;
  210. }
  211. /**
  212. * Return type of {@link useLink}.
  213. * @internal
  214. */
  215. interface UseLinkReturn<Name extends keyof RouteMap = keyof RouteMap> {
  216. route: ComputedRef<RouteLocationResolved<Name>>;
  217. href: ComputedRef<string>;
  218. isActive: ComputedRef<boolean>;
  219. isExactActive: ComputedRef<boolean>;
  220. navigate(e?: MouseEvent): Promise<void | NavigationFailure>;
  221. }
  222. /**
  223. * Returns the internal behavior of a {@link RouterLink} without the rendering part.
  224. *
  225. * @param props - a `to` location and an optional `replace` flag
  226. */
  227. declare function useLink<Name extends keyof RouteMap = keyof RouteMap>(props: UseLinkOptions<Name>): UseLinkReturn<Name>;
  228. /**
  229. * Component to render a link that triggers a navigation on click.
  230. */
  231. declare const RouterLink: _RouterLinkI;
  232. /**
  233. * @internal
  234. */
  235. type _RouterLinkPropsTypedBase = AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterLinkProps;
  236. /**
  237. * @internal
  238. */
  239. type RouterLinkPropsTyped<Custom extends boolean | undefined> = Custom extends true ? _RouterLinkPropsTypedBase & {
  240. custom: true;
  241. } : _RouterLinkPropsTypedBase & {
  242. custom?: false | undefined;
  243. } & Omit<AnchorHTMLAttributes, 'href'>;
  244. /**
  245. * Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
  246. * automatically for JSX.
  247. *
  248. * @internal
  249. */
  250. interface _RouterLinkI {
  251. new <Custom extends boolean | undefined = boolean | undefined>(): {
  252. $props: RouterLinkPropsTyped<Custom>;
  253. $slots: {
  254. default?: ({
  255. route,
  256. href,
  257. isActive,
  258. isExactActive,
  259. navigate
  260. }: UnwrapRef<UseLinkReturn>) => VNode[];
  261. };
  262. };
  263. /**
  264. * Access to `useLink()` without depending on using vue-router
  265. *
  266. * @internal
  267. */
  268. useLink: typeof useLink;
  269. }
  270. //#endregion
  271. //#region src/RouterView.d.ts
  272. interface RouterViewProps {
  273. name?: string;
  274. route?: RouteLocationNormalized;
  275. }
  276. /**
  277. * Component to display the current route the user is at.
  278. */
  279. declare const RouterView: {
  280. new (): {
  281. $props: AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterViewProps;
  282. $slots: {
  283. default?: ({
  284. Component,
  285. route
  286. }: {
  287. Component: VNode;
  288. route: RouteLocationNormalizedLoaded;
  289. }) => VNode[];
  290. };
  291. };
  292. };
  293. //#endregion
  294. //#region src/useApi.d.ts
  295. /**
  296. * Returns the router instance. Equivalent to using `$router` inside
  297. * templates.
  298. */
  299. declare function useRouter(): Router;
  300. /**
  301. * Returns the current route location. Equivalent to using `$route` inside
  302. * templates.
  303. */
  304. declare function useRoute<Name extends keyof RouteMap = keyof RouteMap>(_name?: Name): RouteLocationNormalizedLoaded<Name | RouteMap[Name]["childrenNames"]>;
  305. //#endregion
  306. //#region src/index.d.ts
  307. declare module 'vue' {
  308. interface ComponentCustomOptions {
  309. /**
  310. * Guard called when the router is navigating to the route that is rendering
  311. * this component from a different route. Differently from `beforeRouteUpdate`
  312. * and `beforeRouteLeave`, `beforeRouteEnter` does not have access to the
  313. * component instance through `this` because it triggers before the component
  314. * is even mounted.
  315. *
  316. * @param to - RouteLocationRaw we are navigating to
  317. * @param from - RouteLocationRaw we are navigating from
  318. * @param next - function to validate, cancel or modify (by redirecting) the
  319. * navigation
  320. */
  321. beforeRouteEnter?: TypesConfig extends Record<'beforeRouteEnter', infer T> ? T : NavigationGuardWithThis<undefined>;
  322. /**
  323. * Guard called whenever the route that renders this component has changed, but
  324. * it is reused for the new route. This allows you to guard for changes in
  325. * params, the query or the hash.
  326. *
  327. * @param to - RouteLocationRaw we are navigating to
  328. * @param from - RouteLocationRaw we are navigating from
  329. * @param next - function to validate, cancel or modify (by redirecting) the
  330. * navigation
  331. */
  332. beforeRouteUpdate?: TypesConfig extends Record<'beforeRouteUpdate', infer T> ? T : NavigationGuard;
  333. /**
  334. * Guard called when the router is navigating away from the current route that
  335. * is rendering this component.
  336. *
  337. * @param to - RouteLocationRaw we are navigating to
  338. * @param from - RouteLocationRaw we are navigating from
  339. * @param next - function to validate, cancel or modify (by redirecting) the
  340. * navigation
  341. */
  342. beforeRouteLeave?: TypesConfig extends Record<'beforeRouteLeave', infer T> ? T : NavigationGuard;
  343. }
  344. interface ComponentCustomProperties {
  345. /**
  346. * Normalized current location. See {@link RouteLocationNormalizedLoaded}.
  347. */
  348. $route: TypesConfig extends Record<'$route', infer T> ? T : RouteLocationNormalizedLoaded;
  349. /**
  350. * {@link Router} instance used by the application.
  351. */
  352. $router: TypesConfig extends Record<'$router', infer T> ? T : Router;
  353. }
  354. interface GlobalComponents {
  355. RouterView: TypesConfig extends Record<'RouterView', infer T> ? T : typeof RouterView;
  356. RouterLink: TypesConfig extends Record<'RouterLink', infer T> ? T : typeof RouterLink;
  357. }
  358. }
  359. //#endregion
  360. export { type ErrorTypes, type HistoryState, type LocationAsRelativeRaw, type LocationQuery, type LocationQueryRaw, type LocationQueryValue, type LocationQueryValueRaw, type MatcherLocation, type MatcherLocationAsPath, type NavigationFailure, NavigationFailureType, type NavigationGuard, type NavigationGuardNext, type NavigationGuardNextCallback, type NavigationGuardReturn, type NavigationGuardWithThis, type NavigationHookAfter, type NavigationRedirectError, type ParamValue, type ParamValueOneOrMore, type ParamValueZeroOrMore, type ParamValueZeroOrOne, type PathParserOptions, type RouteComponent, type RouteLocation, type RouteLocationAsPath, type RouteLocationAsPathGeneric, type RouteLocationAsPathTyped, type RouteLocationAsPathTypedList, type RouteLocationAsRelative, type RouteLocationAsRelativeGeneric, type RouteLocationAsRelativeTyped, type RouteLocationAsRelativeTypedList, type RouteLocationAsString, type RouteLocationAsStringTyped, type RouteLocationAsStringTypedList, type RouteLocationGeneric, type RouteLocationMatched, type RouteLocationNamedRaw, type RouteLocationNormalized, type RouteLocationNormalizedGeneric, type RouteLocationNormalizedLoaded, type RouteLocationNormalizedLoadedGeneric, type RouteLocationNormalizedLoadedTyped, type RouteLocationNormalizedLoadedTypedList, type RouteLocationNormalizedTyped, type RouteLocationNormalizedTypedList, type RouteLocationOptions, type RouteLocationPathRaw, type RouteLocationRaw, type RouteLocationResolved, type RouteLocationResolvedGeneric, type RouteLocationResolvedTyped, type RouteLocationResolvedTypedList, type RouteLocationTyped, type RouteLocationTypedList, type RouteMap, type RouteMapGeneric, type RouteMeta, type RouteParamValue, type RouteParamValueRaw, type RouteParams, type RouteParamsGeneric, type RouteParamsRaw, type RouteParamsRawGeneric, type RouteQueryAndHash, type RouteRecord, type RouteRecordInfo, type RouteRecordInfoGeneric, type RouteRecordMultipleViews, type RouteRecordMultipleViewsWithChildren, type RouteRecordName, type RouteRecordNameGeneric, type RouteRecordNormalized, type RouteRecordRaw, type RouteRecordRedirect, type RouteRecordRedirectOption, type RouteRecordSingleView, type RouteRecordSingleViewWithChildren, type Router, type RouterHistory, RouterLink, type RouterLinkProps, type RouterMatcher, type RouterOptions, type RouterScrollBehavior, RouterView, type RouterViewProps, START_LOCATION_NORMALIZED as START_LOCATION, type TypesConfig, type UseLinkOptions, type UseLinkReturn, type _Awaitable, type _PathParserOptions, type _RouteLocationBase, type _RouteRecordBase, type _RouteRecordProps, type _RouterLinkI, createMemoryHistory, createRouter, createRouterMatcher, createWebHashHistory, createWebHistory, isNavigationFailure, loadRouteLocation, matchedRouteKey, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, routeLocationKey, routerKey, routerViewLocationKey, stringifyQuery, useLink, useRoute, useRouter, viewDepthKey };