Skip to content

feat(types): add composables.d.ts in root #3784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composables.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types/composables'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dist/*.js",
"dist/*.mjs",
"types/*.d.ts",
"composables.d.ts",
"vetur/tags.json",
"vetur/attributes.json"
],
Expand Down
86 changes: 42 additions & 44 deletions types/composables.d.ts
Original file line number Diff line number Diff line change
@@ -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<Route>
/**
* Calls `router.replace` instead of `router.push`.
*/
replace?: boolean
}

to: Route | Ref<Route>
/**
* 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<Route>,
isActive: ComputedRef<boolean>,
isExactActive: ComputedRef<boolean>,
href: ComputedRef<string>,
navigate: () => Promise<void>,
}
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<Route>,
isActive: ComputedRef<boolean>,
isExactActive: ComputedRef<boolean>,
href: ComputedRef<string>,
navigate: () => Promise<void>,
}