mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(kit, nuxt): support prerender:routes
and addPrerenderRoutes
(#8670)
This commit is contained in:
parent
9a67b9e4f3
commit
ea17148a6b
@ -31,7 +31,7 @@ Hook | Arguments | Environment | Description
|
||||
|
||||
# Nuxt Hooks (build time)
|
||||
|
||||
Check the [schema source code](https://github.com/nuxt/framework/blob/main/packages/schema/src/types/hooks.ts#L69) for all available hooks.
|
||||
Check the [schema source code](https://github.com/nuxt/framework/blob/main/packages/schema/src/types/hooks.ts#L53) for all available hooks.
|
||||
|
||||
:NeedContribution
|
||||
|
||||
|
@ -77,6 +77,8 @@ description: Nuxt Kit provides composable utilities to help interacting with Nux
|
||||
- `addServerHandler (handler)`
|
||||
- `addDevServerHandler (handler)`
|
||||
- `useNitro()` (only usable after `ready` hook)
|
||||
- `addServerPlugin`
|
||||
- `addPrerenderRoutes`
|
||||
|
||||
### Resolving
|
||||
|
||||
|
@ -41,6 +41,25 @@ export function addServerPlugin (plugin: string) {
|
||||
nuxt.options.nitro.plugins.push(normalize(plugin))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds routes to be prerendered
|
||||
*/
|
||||
export function addPrerenderRoutes (routes: string | string[]) {
|
||||
const nuxt = useNuxt()
|
||||
if (!Array.isArray(routes)) {
|
||||
routes = [routes]
|
||||
}
|
||||
routes = routes.filter(Boolean)
|
||||
if (!routes.length) {
|
||||
return
|
||||
}
|
||||
nuxt.hook('prerender:routes', (ctx) => {
|
||||
for (const route of routes) {
|
||||
ctx.routes.add(route)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to the Nitro instance
|
||||
*
|
||||
|
@ -148,6 +148,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
|
||||
// Connect hooks
|
||||
nuxt.hook('close', () => nitro.hooks.callHook('close'))
|
||||
nitro.hooks.hook('prerender:routes', (routes) => {
|
||||
nuxt.callHook('prerender:routes', { routes })
|
||||
})
|
||||
|
||||
// Setup handlers
|
||||
const devMiddlewareHandler = dynamicEventHandler()
|
||||
|
@ -96,6 +96,7 @@ export interface NuxtHooks {
|
||||
'nitro:config': (nitroConfig: NitroConfig) => HookResult
|
||||
'nitro:init': (nitro: Nitro) => HookResult
|
||||
'nitro:build:before': (nitro: Nitro) => HookResult
|
||||
'prerender:routes': (ctx: { routes: Set<string> }) => HookResult
|
||||
|
||||
// Nuxi
|
||||
'build:error': (error: Error) => HookResult
|
||||
|
Loading…
Reference in New Issue
Block a user