vue-router.d.mts 18 KB

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