mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
fix(nuxt-link): handle state without href and to
This commit is contained in:
parent
04026a3861
commit
970a4d36d5
@ -21,5 +21,6 @@
|
|||||||
<MyNuxtLink to="/">
|
<MyNuxtLink to="/">
|
||||||
Index page with a custom link component with a custom active class
|
Index page with a custom link component with a custom active class
|
||||||
</MyNuxtLink>
|
</MyNuxtLink>
|
||||||
|
<NuxtLink>Link without href and to</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -141,8 +141,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directly check if `to` is an external URL by checking protocol
|
return to.value === '' || hasProtocol(to.value, true)
|
||||||
return hasProtocol(to.value, true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@ -171,10 +170,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
|
|
||||||
// Resolves `rel`
|
// Resolves `rel`
|
||||||
checkPropConflicts(props, 'noRel', 'rel')
|
checkPropConflicts(props, 'noRel', 'rel')
|
||||||
const rel = props.noRel
|
const rel = (props.noRel)
|
||||||
? null
|
? null
|
||||||
// converts `""` to `null` to prevent the attribute from being added as empty (`rel=""`)
|
// converts `""` to `null` to prevent the attribute from being added as empty (`rel=""`)
|
||||||
: firstNonUndefined<string | null>(props.rel, options.externalRelAttribute, DEFAULT_EXTERNAL_REL_ATTRIBUTE) || null
|
: firstNonUndefined<string | null>(props.rel, options.externalRelAttribute, href ? DEFAULT_EXTERNAL_REL_ATTRIBUTE : '') || null
|
||||||
|
|
||||||
return h('a', { href, rel, target }, slots.default())
|
return h('a', { href, rel, target }, slots.default())
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,10 @@ describe('nuxt-link:to', () => {
|
|||||||
consoleWarnSpy.mockRestore()
|
consoleWarnSpy.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('defaults to `null`', () => {
|
it('without to and href', () => {
|
||||||
expect(nuxtLink().props.href).toBe(null)
|
const link = nuxtLink()
|
||||||
|
expect(link.props.href).toBe(null)
|
||||||
|
expect(link.props.rel).toBe(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user