mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +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="/">
|
||||
Index page with a custom link component with a custom active class
|
||||
</MyNuxtLink>
|
||||
<NuxtLink>Link without href and to</NuxtLink>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -141,8 +141,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Directly check if `to` is an external URL by checking protocol
|
||||
return hasProtocol(to.value, true)
|
||||
return to.value === '' || hasProtocol(to.value, true)
|
||||
})
|
||||
|
||||
return () => {
|
||||
@ -171,10 +170,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
|
||||
// Resolves `rel`
|
||||
checkPropConflicts(props, 'noRel', 'rel')
|
||||
const rel = props.noRel
|
||||
const rel = (props.noRel)
|
||||
? null
|
||||
// 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())
|
||||
}
|
||||
|
@ -53,8 +53,10 @@ describe('nuxt-link:to', () => {
|
||||
consoleWarnSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('defaults to `null`', () => {
|
||||
expect(nuxtLink().props.href).toBe(null)
|
||||
it('without to and href', () => {
|
||||
const link = nuxtLink()
|
||||
expect(link.props.href).toBe(null)
|
||||
expect(link.props.rel).toBe(null)
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user