-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
check-if-page-unused.ts
30 lines (27 loc) · 1000 Bytes
/
check-if-page-unused.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { nextTick } from 'vue'
import { defineNuxtPlugin } from '#app/nuxt'
import { onNuxtReady } from '#app/composables/ready'
import { useError } from '#app/composables/error'
export default defineNuxtPlugin({
name: 'nuxt:checkIfPageUnused',
setup (nuxtApp) {
const error = useError()
function checkIfPageUnused () {
if (!error.value && !nuxtApp._isNuxtPageUsed) {
console.warn(
'[nuxt] Your project has pages but the `<NuxtPage />` component has not been used.' +
' You might be using the `<RouterView />` component instead, which will not work correctly in Nuxt.' +
' You can set `pages: false` in `nuxt.config` if you do not wish to use the Nuxt `vue-router` integration.'
)
}
}
if (import.meta.server) {
nuxtApp.hook('app:rendered', ({ renderResult }) => { renderResult?.html && nextTick(checkIfPageUnused) })
} else {
onNuxtReady(checkIfPageUnused)
}
},
env: {
islands: false
}
})