Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c69e4c3

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

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/app/app-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,17 @@ describe('typed router integration', () => {
263263
it('allows typing NuxtLink', () => {
264264
// @ts-expect-error this named route does not exist
265265
h(NuxtLink, { to: { name: 'some-thing' } })
266+
// @ts-expect-error this named route does not exist
267+
h(NuxtLink, { href: { name: 'some-thing' } })
266268
// this one does
267269
h(NuxtLink, { to: { name: 'page' } })
270+
h(NuxtLink, { href: { name: 'page' } })
268271
// @ts-expect-error this is an invalid param
269272
h(NuxtLink, { to: { name: 'param-id', params: { bob: 23 } } })
273+
// @ts-expect-error this is an invalid param
274+
h(NuxtLink, { href: { name: 'param-id', params: { bob: 23 } } })
270275
h(NuxtLink, { to: { name: 'param-id', params: { id: 4 } } })
276+
h(NuxtLink, { href: { name: 'param-id', params: { id: 4 } } })
271277

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

0 commit comments

Comments
 (0)