feat: pages:resolved hook

This commit is contained in:
Bobbie Goede 2024-09-05 22:30:53 +02:00
parent 181d043eaf
commit 9d387f722c
2 changed files with 12 additions and 8 deletions

View File

@ -64,17 +64,14 @@ export async function resolvePagesRoutes (): Promise<NuxtPage[]> {
shouldUseServerComponents: !!nuxt.options.experimental.componentIslands,
})
const pages = uniqueBy(allRoutes, 'path')
const shouldAugment = nuxt.options.experimental.scanPageMeta || nuxt.options.experimental.typedPages
const pages = uniqueBy(allRoutes, 'path')
await nuxt.callHook('pages:extend', pages)
if (shouldAugment) {
const augmentedPages = await augmentPages(pages, nuxt.vfs)
await nuxt.callHook('pages:extend', pages)
await augmentPages(pages, nuxt.vfs, augmentedPages)
augmentedPages.clear()
} else {
await nuxt.callHook('pages:extend', pages)
await augmentPages(pages, nuxt.vfs)
await nuxt.callHook('pages:resolved', pages)
}
return pages

View File

@ -189,6 +189,13 @@ export interface NuxtHooks {
*/
'pages:extend': (pages: NuxtPage[]) => HookResult
/**
* Called after pages routes are resolved.
* @param pages Array containing resolved pages
* @returns Promise
*/
'pages:resolved': (pages: NuxtPage[]) => HookResult
/**
* Called when resolving `app/router.options` files. It allows modifying the detected router options files
* and adding new ones.