Skip to content

Commit 0cf54de

Browse files
authored
feat(types): add composables.d.ts in root (#3784)
1 parent 03effee commit 0cf54de

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

composables.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types/composables'

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dist/*.js",
2020
"dist/*.mjs",
2121
"types/*.d.ts",
22+
"composables.d.ts",
2223
"vetur/tags.json",
2324
"vetur/attributes.json"
2425
],

types/composables.d.ts

+42-44
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
declare module 'vue-router/composables' {
2-
import type { ComputedRef, Ref } from 'vue'
3-
import type { Route, NavigationGuard, default as VueRouter } from 'vue-router'
1+
import type { ComputedRef, Ref } from 'vue'
2+
import type { Route, NavigationGuard, default as VueRouter } from './index'
43

5-
/**
6-
* Returns the current route location. Equivalent to using `$route` inside templates.
7-
*/
8-
export function useRoute(): Route
4+
/**
5+
* Returns the current route location. Equivalent to using `$route` inside templates.
6+
*/
7+
export function useRoute(): Route
98

10-
/**
11-
* Returns the router instance. Equivalent to using `$router` inside templates.
12-
*/
13-
export function useRouter(): VueRouter
9+
/**
10+
* Returns the router instance. Equivalent to using `$router` inside templates.
11+
*/
12+
export function useRouter(): VueRouter
1413

15-
/**
16-
* 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.
17-
*
18-
* @param updateGuard
19-
*/
20-
export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
14+
/**
15+
* 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.
16+
*
17+
* @param updateGuard
18+
*/
19+
export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
2120

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

0 commit comments

Comments
 (0)