// @ts-ignore
ComponentOptionsMixin,
MaybeRef,
+ AnchorHTMLAttributes,
} from 'vue'
import { isSameRouteLocationParams, isSameRouteRecord } from './location'
import { routerKey, routeLocationKey } from './injectionSymbols'
*/
export const RouterLink: _RouterLinkI = RouterLinkImpl as any
+/**
+ * @internal
+ */
+type _RouterLinkPropsTypedBase = AllowedComponentProps &
+ ComponentCustomProps &
+ VNodeProps &
+ RouterLinkProps
+
+/**
+ * @internal
+ */
+type RouterLinkPropsTyped<Custom extends boolean | undefined> =
+ Custom extends true
+ ? _RouterLinkPropsTypedBase & { custom: true }
+ : _RouterLinkPropsTypedBase & { custom?: false | undefined } & Omit<
+ AnchorHTMLAttributes,
+ 'href'
+ >
+
/**
* Typed version of the `RouterLink` component. Its generic defaults to the typed router, so it can be inferred
* automatically for JSX.
* @internal
*/
export interface _RouterLinkI {
- new (): {
- $props: AllowedComponentProps &
- ComponentCustomProps &
- VNodeProps &
- RouterLinkProps
+ new <Custom extends boolean | undefined = boolean | undefined>(): {
+ $props: RouterLinkPropsTyped<Custom>
$slots: {
default?: ({
expectTypeOf<JSX.Element>(<RouterLink class="link" to="/foo" />)
expectTypeOf<JSX.Element>(<RouterLink to={{ path: '/foo' }} />)
expectTypeOf<JSX.Element>(<RouterLink to={{ path: '/foo' }} custom />)
+ // event handlers and anchor attrs are allowed when not custom
+ expectTypeOf<JSX.Element>(
+ <RouterLink to="/" onFocus={() => {}} onClick={() => {}} />
+ )
+ expectTypeOf<JSX.Element>(
+ <RouterLink to="/" target="_blank" rel="noopener" />
+ )
+ // @ts-expect-error: href is intentionally omitted
+ expectError(<RouterLink to="/" href="/bar" />)
+ // @ts-expect-error: onFocus should not be allowed with custom
+ expectError(<RouterLink to="/" custom onFocus={() => {}} />)
// RouterView
expectTypeOf<JSX.Element>(<RouterView class="view" />)