Skip to content

Commit b97ae2f

Browse files
committed
fix(nuxt): allow object-format href in <NuxtLink>
1 parent 1c48884 commit b97ae2f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/nuxt/src/app/components/nuxt-link.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
422422

423423
return () => {
424424
if (!isExternal.value && !hasTarget.value && !isHashLinkWithoutHashMode(to.value)) {
425-
const routerLinkProps: RouterLinkProps & VNodeProps & AllowedComponentProps & AnchorHTMLAttributes = {
425+
const routerLinkProps: RouterLinkProps & VNodeProps & AllowedComponentProps & Omit<AnchorHTMLAttributes, 'href'> = {
426426
ref: elRef,
427427
to: to.value,
428428
activeClass: props.activeClass || options.activeClass,
@@ -527,7 +527,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
527527
},
528528
// }) as unknown as DefineComponent<NuxtLinkProps, object, object, ComputedOptions, MethodOptions, object, object, EmitsOptions, string, object, NuxtLinkProps, object, SlotsType<NuxtLinkSlots>>
529529
}) as unknown as (new<CustomProp extends boolean = false>(props: NuxtLinkProps<CustomProp> & VNodeProps & AllowedComponentProps & AnchorHTMLAttributes) => InstanceType<DefineSetupFnComponent<
530-
NuxtLinkProps<CustomProp> & VNodeProps & AllowedComponentProps & AnchorHTMLAttributes,
530+
NuxtLinkProps<CustomProp> & VNodeProps & AllowedComponentProps & Omit<AnchorHTMLAttributes, 'href'>,
531531
[],
532532
SlotsType<NuxtLinkSlots<CustomProp>>
533533
>>) & Record<string, any>

test/fixtures/basic-types/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,17 @@ describe('typed router integration', () => {
265265
it('allows typing NuxtLink', () => {
266266
// @ts-expect-error this named route does not exist
267267
h(NuxtLink, { to: { name: 'some-thing' } })
268+
// @ts-expect-error this named route does not exist
269+
h(NuxtLink, { href: { name: 'some-thing' } })
268270
// this one does
269271
h(NuxtLink, { to: { name: 'page' } })
272+
h(NuxtLink, { href: { name: 'page' } })
270273
// @ts-expect-error this is an invalid param
271274
h(NuxtLink, { to: { name: 'param-id', params: { bob: 23 } } })
275+
// @ts-expect-error this is an invalid param
276+
h(NuxtLink, { href: { name: 'param-id', params: { bob: 23 } } })
272277
h(NuxtLink, { to: { name: 'param-id', params: { id: 4 } } })
278+
h(NuxtLink, { href: { name: 'param-id', params: { id: 4 } } })
273279

274280
// doesn't throw an error when accessing properties of component
275281
const _props = NuxtLink.props

0 commit comments

Comments
 (0)