From 0cf54de782a0b05692bbe78a7181495b6a35b8d9 Mon Sep 17 00:00:00 2001 From: ZHAO Jinxiang Date: Wed, 24 Aug 2022 23:18:26 -0700 Subject: [PATCH] feat(types): add composables.d.ts in root (#3784) --- composables.d.ts | 1 + package.json | 1 + types/composables.d.ts | 86 +++++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 composables.d.ts diff --git a/composables.d.ts b/composables.d.ts new file mode 100644 index 000000000..790fbfba8 --- /dev/null +++ b/composables.d.ts @@ -0,0 +1 @@ +export * from './types/composables' diff --git a/package.json b/package.json index 292d0a141..f26187941 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dist/*.js", "dist/*.mjs", "types/*.d.ts", + "composables.d.ts", "vetur/tags.json", "vetur/attributes.json" ], diff --git a/types/composables.d.ts b/types/composables.d.ts index f20e1b218..981f7a2ab 100644 --- a/types/composables.d.ts +++ b/types/composables.d.ts @@ -1,53 +1,51 @@ -declare module 'vue-router/composables' { - import type { ComputedRef, Ref } from 'vue' - import type { Route, NavigationGuard, default as VueRouter } from 'vue-router' +import type { ComputedRef, Ref } from 'vue' +import type { Route, NavigationGuard, default as VueRouter } from './index' - /** - * Returns the current route location. Equivalent to using `$route` inside templates. - */ - export function useRoute(): Route +/** + * Returns the current route location. Equivalent to using `$route` inside templates. + */ +export function useRoute(): Route - /** - * Returns the router instance. Equivalent to using `$router` inside templates. - */ - export function useRouter(): VueRouter +/** + * Returns the router instance. Equivalent to using `$router` inside templates. + */ +export function useRouter(): VueRouter - /** - * Add a navigation guard that triggers whenever the current location is about to be updated. Similar to beforeRouteUpdate but can be used in any component. The guard is removed when the component is unmounted. - * - * @param updateGuard - */ - export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void +/** + * Add a navigation guard that triggers whenever the current location is about to be updated. Similar to beforeRouteUpdate but can be used in any component. The guard is removed when the component is unmounted. + * + * @param updateGuard + */ +export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void +/** + * Add a navigation guard that triggers whenever the component for the current location is about to be left. Similar to beforeRouteLeave but can be used in any component. The guard is removed when the component is unmounted. + * + * @param leaveGuard + */ +export function onBeforeRouteLeave(leaveGuard: NavigationGuard): void + +export interface RouterLinkOptions { /** - * Add a navigation guard that triggers whenever the component for the current location is about to be left. Similar to beforeRouteLeave but can be used in any component. The guard is removed when the component is unmounted. - * - * @param leaveGuard + * Route Location the link should navigate to when clicked on. */ - export function onBeforeRouteLeave(leaveGuard: NavigationGuard): void - - export interface RouterLinkOptions { - /** - * Route Location the link should navigate to when clicked on. - */ - to: Route | Ref - /** - * Calls `router.replace` instead of `router.push`. - */ - replace?: boolean - } - + to: Route | Ref /** - * Vue Router 4 `useLink()` function. Note the active behavior is different from Vue Router 3 as highlighted in the - * migration guide (https://router.vuejs.org/guide/migration/index.html#removal-of-the-exact-prop-in-router-link) - * - * @param props - object containing a `to` property with the location + * Calls `router.replace` instead of `router.push`. */ - export function useLink(props: RouterLinkOptions): { - route: ComputedRef, - isActive: ComputedRef, - isExactActive: ComputedRef, - href: ComputedRef, - navigate: () => Promise, - } + replace?: boolean +} + +/** + * Vue Router 4 `useLink()` function. Note the active behavior is different from Vue Router 3 as highlighted in the + * migration guide (https://router.vuejs.org/guide/migration/index.html#removal-of-the-exact-prop-in-router-link) + * + * @param props - object containing a `to` property with the location + */ +export function useLink({ to, replace }: RouterLinkOptions): { + route: ComputedRef, + isActive: ComputedRef, + isExactActive: ComputedRef, + href: ComputedRef, + navigate: () => Promise, }