File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Expand file tree Collapse file tree 2 files changed +33
-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'
@@ -359,18 +360,34 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
359
360
*/
360
361
export const RouterLink : _RouterLinkI = RouterLinkImpl as any
361
362
363
+ /**
364
+ * @internal
365
+ */
366
+ type _RouterLinkPropsTypedBase = AllowedComponentProps &
367
+ ComponentCustomProps &
368
+ VNodeProps &
369
+ RouterLinkProps
370
+
371
+ /**
372
+ * @internal
373
+ */
374
+ type RouterLinkPropsTyped < Custom extends boolean | undefined > =
375
+ Custom extends true
376
+ ? _RouterLinkPropsTypedBase & { custom : true }
377
+ : _RouterLinkPropsTypedBase & { custom ?: false | undefined } & Omit <
378
+ AnchorHTMLAttributes ,
379
+ 'href'
380
+ >
381
+
362
382
/**
363
383
* Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
364
384
* automatically for JSX.
365
385
*
366
386
* @internal
367
387
*/
368
388
export interface _RouterLinkI {
369
- new ( ) : {
370
- $props : AllowedComponentProps &
371
- ComponentCustomProps &
372
- VNodeProps &
373
- RouterLinkProps
389
+ new < Custom extends boolean | undefined = boolean | undefined > ( ) : {
390
+ $props : RouterLinkPropsTyped < Custom >
374
391
375
392
$slots : {
376
393
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