File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import {
26
26
// @ts -ignore
27
27
ComponentOptionsMixin ,
28
28
MaybeRef ,
29
+ AnchorHTMLAttributes ,
29
30
} from 'vue'
30
31
import { isSameRouteLocationParams , isSameRouteRecord } from './location'
31
32
import { routerKey , routeLocationKey } from './injectionSymbols'
@@ -365,12 +366,20 @@ export const RouterLink: _RouterLinkI = RouterLinkImpl as any
365
366
*
366
367
* @internal
367
368
*/
369
+ type LinkAnchorAttrs = Omit < AnchorHTMLAttributes , 'href' >
370
+
371
+ type _BaseRouterLinkProps = AllowedComponentProps &
372
+ ComponentCustomProps &
373
+ VNodeProps &
374
+ RouterLinkProps
375
+
376
+ type RouterLinkTypedProps < C extends boolean | undefined > = C extends true
377
+ ? _BaseRouterLinkProps & { custom : true }
378
+ : _BaseRouterLinkProps & { custom ?: false | undefined } & LinkAnchorAttrs
379
+
368
380
export interface _RouterLinkI {
369
- new ( ) : {
370
- $props : AllowedComponentProps &
371
- ComponentCustomProps &
372
- VNodeProps &
373
- RouterLinkProps
381
+ new < C extends boolean | undefined = boolean | undefined > ( ) : {
382
+ $props : RouterLinkTypedProps < C >
374
383
375
384
$slots : {
376
385
default ?: ( {
Original file line number Diff line number Diff line change @@ -27,6 +27,17 @@ describe('Components', () => {
27
27
expectTypeOf < JSX . Element > ( < RouterLink class = "link" to = "/foo" /> )
28
28
expectTypeOf < JSX . Element > ( < RouterLink to = { { path : '/foo' } } /> )
29
29
expectTypeOf < JSX . Element > ( < RouterLink to = { { path : '/foo' } } custom /> )
30
+ // event handlers and anchor attrs are allowed when not custom
31
+ expectTypeOf < JSX . Element > (
32
+ < RouterLink to = "/" onFocus = { ( ) => { } } onClick = { ( ) => { } } />
33
+ )
34
+ expectTypeOf < JSX . Element > (
35
+ < RouterLink to = "/" target = "_blank" rel = "noopener" />
36
+ )
37
+ // @ts -expect-error: href is intentionally omitted
38
+ expectError ( < RouterLink to = "/" href = "/bar" /> )
39
+ // @ts -expect-error: onFocus should not be allowed with custom
40
+ expectError ( < RouterLink to = "/" custom onFocus = { ( ) => { } } /> )
30
41
31
42
// RouterView
32
43
expectTypeOf < JSX . Element > ( < RouterView class = "view" /> )
You can’t perform that action at this time.
0 commit comments