@@ -31,26 +31,35 @@ import {
31
31
VueUseOptions ,
32
32
RouteLocation ,
33
33
RouteLocationNormalized ,
34
+ RouteLocationPathRaw ,
35
+ RouteLocationString ,
36
+ RouteLocationNamedRaw ,
34
37
} from './types'
35
38
import { isSameRouteLocationParams , isSameRouteRecord } from './___location'
36
39
import { routerKey , routeLocationKey } from './injectionSymbols'
37
40
import { RouteRecord } from './matcher/types'
38
41
import { NavigationFailure } from './errors'
39
42
import { isArray , isBrowser , noop } from './utils'
43
+ import type { Router } from './router'
44
+ import { RouteNamedMap , RouteStaticPathMap } from './types/named'
40
45
41
- export interface RouterLinkOptions {
46
+ export interface RouterLinkOptions <
47
+ Routes extends RouteLocationRaw = RouteLocationRaw
48
+ > {
42
49
/**
43
50
* Route Location the link should navigate to when clicked on.
44
51
*/
45
- to : RouteLocationRaw
52
+ to : Routes
46
53
/**
47
54
* Calls `router.replace` instead of `router.push`.
48
55
*/
49
56
replace ?: boolean
50
57
// TODO: refactor using extra options allowed in router.push. Needs RFC
51
58
}
52
59
53
- export interface RouterLinkProps extends RouterLinkOptions {
60
+ export interface RouterLinkProps <
61
+ Routes extends RouteLocationRaw = RouteLocationRaw
62
+ > extends RouterLinkOptions < Routes > {
54
63
/**
55
64
* Whether RouterLink should not wrap its content in an `a` tag. Useful when
56
65
* using `v-slot` to create a custom RouterLink
@@ -251,12 +260,18 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
251
260
/**
252
261
* Component to render a link that triggers a navigation on click.
253
262
*/
254
- export const RouterLink = RouterLinkImpl as unknown as {
263
+ export const RouterLink = RouterLinkImpl as unknown as RouterLinkTyped
264
+
265
+ export interface RouterLinkTyped < R extends Router = Router > {
255
266
new ( ) : {
256
267
$props : AllowedComponentProps &
257
268
ComponentCustomProps &
258
269
VNodeProps &
259
- RouterLinkProps
270
+ RouterLinkProps <
271
+ | RouteLocationNamedRaw < RouteNamedMap < R [ 'options' ] [ 'routes' ] > >
272
+ | RouteLocationString < RouteStaticPathMap < R [ 'options' ] [ 'routes' ] > >
273
+ | RouteLocationPathRaw < RouteStaticPathMap < R [ 'options' ] [ 'routes' ] > >
274
+ >
260
275
261
276
$slots : {
262
277
default : ( arg : UnwrapRef < ReturnType < typeof useLink > > ) => VNode [ ]
0 commit comments