Skip to content

Commit 77bd0e3

Browse files
committed
feat(types): useLink()
1 parent 5613b77 commit 77bd0e3

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

types/composables.d.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
declare module 'vue-router/composables' {
2+
import type { ComputedRef, Ref } from 'vue'
23
import type { Route, NavigationGuard, default as VueRouter } from 'vue-router'
34

45
/**
@@ -14,14 +15,39 @@ declare module 'vue-router/composables' {
1415
/**
1516
* 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.
1617
*
17-
* @param updateGuard NavigationGuard
18+
* @param updateGuard
1819
*/
1920
export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
2021

2122
/**
2223
* 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.
2324
*
24-
* @param leaveGuard NavigationGuard
25+
* @param leaveGuard
2526
*/
2627
export function onBeforeRouteLeave(leaveGuard: NavigationGuard): void
28+
29+
export interface RouterLinkOptions {
30+
/**
31+
* Route Location the link should navigate to when clicked on.
32+
*/
33+
to: Route | Ref<Route>
34+
/**
35+
* Calls `router.replace` instead of `router.push`.
36+
*/
37+
replace?: boolean
38+
}
39+
40+
/**
41+
* Vue Router 4 `useLink()` function. Note the active behavior is different from Vue Router 3 as highlighted in the
42+
* migration guide (https://router.vuejs.org/guide/migration/index.html#removal-of-the-exact-prop-in-router-link)
43+
*
44+
* @param props - object containing a `to` property with the location
45+
*/
46+
export function useLink(props: RouterLinkOptions): {
47+
route: ComputedRef<Route>,
48+
isActive: ComputedRef<boolean>,
49+
isExactActive: ComputedRef<boolean>,
50+
href: ComputedRef<string>,
51+
navigate: () => Promise<void>,
52+
}
2753
}

0 commit comments

Comments
 (0)