Skip to content

Commit

Permalink
feat(types): useLink()
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Aug 22, 2022
1 parent 5613b77 commit 77bd0e3
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions types/composables.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module 'vue-router/composables' {
import type { ComputedRef, Ref } from 'vue'
import type { Route, NavigationGuard, default as VueRouter } from 'vue-router'

/**
Expand All @@ -14,14 +15,39 @@ declare module 'vue-router/composables' {
/**
* 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 NavigationGuard
* @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 NavigationGuard
* @param leaveGuard
*/
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
}

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

0 comments on commit 77bd0e3

Please sign in to comment.