(nuxtApp)
| 11 | export default defineNuxtPlugin({ |
| 12 | name: 'nuxt:prefetch', |
| 13 | setup (nuxtApp) { |
| 14 | const router = useRouter() |
| 15 | |
| 16 | // Force layout prefetch on route changes |
| 17 | nuxtApp.hooks.hook('app:mounted', () => { |
| 18 | router.beforeEach(async (to) => { |
| 19 | const layout = to?.meta?.layout |
| 20 | if (layout && typeof layouts[layout] === 'function') { |
| 21 | await layouts[layout]() |
| 22 | } |
| 23 | }) |
| 24 | }) |
| 25 | // Prefetch layouts & middleware |
| 26 | nuxtApp.hooks.hook('link:prefetch', (url) => { |
| 27 | if (hasProtocol(url)) { return } |
| 28 | const route = router.resolve(url) |
| 29 | if (!route) { return } |
| 30 | const layout = route.meta.layout |
| 31 | let middleware = toArray(route.meta.middleware) |
| 32 | middleware = middleware.filter(m => typeof m === 'string') |
| 33 | |
| 34 | for (const name of middleware) { |
| 35 | if (typeof namedMiddleware[name] === 'function') { |
| 36 | namedMiddleware[name]() |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (typeof layout === 'string' && layout in layouts) { |
| 41 | _loadAsyncComponent(layouts[layout]) |
| 42 | } |
| 43 | }) |
| 44 | }, |
| 45 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…