mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(nuxt): check if default slot is provided before calling it (#4842)
This commit is contained in:
parent
4079882bd4
commit
750460693e
@ -175,7 +175,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
// 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, href ? 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?.())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) as unknown as DefineComponent<NuxtLinkProps>
|
}) as unknown as DefineComponent<NuxtLinkProps>
|
||||||
|
@ -3,7 +3,7 @@ import type { Component } from 'vue'
|
|||||||
|
|
||||||
const Fragment = {
|
const Fragment = {
|
||||||
setup (_props, { slots }) {
|
setup (_props, { slots }) {
|
||||||
return () => slots.default()
|
return () => slots.default?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ export const Base = defineComponent({
|
|||||||
export const Title = defineComponent({
|
export const Title = defineComponent({
|
||||||
name: 'Title',
|
name: 'Title',
|
||||||
setup: setupForUseMeta((_, { slots }) => {
|
setup: setupForUseMeta((_, { slots }) => {
|
||||||
const title = slots.default()?.[0]?.children || null
|
const title = slots.default?.()?.[0]?.children || null
|
||||||
if (process.dev && title && typeof title !== 'string') {
|
if (process.dev && title && typeof title !== 'string') {
|
||||||
console.error('<Title> can only take a string in its default slot.')
|
console.error('<Title> can only take a string in its default slot.')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user