fix(nuxt): do not warn about missing layouts on error page (#25008)

This commit is contained in:
Daniel Roe 2024-01-02 16:13:01 +00:00 committed by GitHub
parent 7087a06c6d
commit ea02e29b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { defineNuxtPlugin } from '../nuxt'
import { onNuxtReady } from '../composables/ready'
import { useError } from '../composables/error'
// @ts-expect-error virtual file
import layouts from '#build/layouts'
@ -7,8 +8,10 @@ import layouts from '#build/layouts'
export default defineNuxtPlugin({
name: 'nuxt:checkIfLayoutUsed',
setup (nuxtApp) {
const error = useError()
function checkIfLayoutUsed () {
if (!nuxtApp._isNuxtLayoutUsed && Object.keys(layouts).length > 0) {
if (!error.value && !nuxtApp._isNuxtLayoutUsed && Object.keys(layouts).length > 0) {
console.warn('[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.')
}
}