mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +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)
|
# 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
|
:NeedContribution
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@ description: Nuxt Kit provides composable utilities to help interacting with Nux
|
|||||||
- `addServerHandler (handler)`
|
- `addServerHandler (handler)`
|
||||||
- `addDevServerHandler (handler)`
|
- `addDevServerHandler (handler)`
|
||||||
- `useNitro()` (only usable after `ready` hook)
|
- `useNitro()` (only usable after `ready` hook)
|
||||||
|
- `addServerPlugin`
|
||||||
|
- `addPrerenderRoutes`
|
||||||
|
|
||||||
### Resolving
|
### Resolving
|
||||||
|
|
||||||
|
@ -41,6 +41,25 @@ export function addServerPlugin (plugin: string) {
|
|||||||
nuxt.options.nitro.plugins.push(normalize(plugin))
|
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
|
* Access to the Nitro instance
|
||||||
*
|
*
|
||||||
|
@ -148,6 +148,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
|||||||
|
|
||||||
// Connect hooks
|
// Connect hooks
|
||||||
nuxt.hook('close', () => nitro.hooks.callHook('close'))
|
nuxt.hook('close', () => nitro.hooks.callHook('close'))
|
||||||
|
nitro.hooks.hook('prerender:routes', (routes) => {
|
||||||
|
nuxt.callHook('prerender:routes', { routes })
|
||||||
|
})
|
||||||
|
|
||||||
// Setup handlers
|
// Setup handlers
|
||||||
const devMiddlewareHandler = dynamicEventHandler()
|
const devMiddlewareHandler = dynamicEventHandler()
|
||||||
|
@ -96,6 +96,7 @@ export interface NuxtHooks {
|
|||||||
'nitro:config': (nitroConfig: NitroConfig) => HookResult
|
'nitro:config': (nitroConfig: NitroConfig) => HookResult
|
||||||
'nitro:init': (nitro: Nitro) => HookResult
|
'nitro:init': (nitro: Nitro) => HookResult
|
||||||
'nitro:build:before': (nitro: Nitro) => HookResult
|
'nitro:build:before': (nitro: Nitro) => HookResult
|
||||||
|
'prerender:routes': (ctx: { routes: Set<string> }) => HookResult
|
||||||
|
|
||||||
// Nuxi
|
// Nuxi
|
||||||
'build:error': (error: Error) => HookResult
|
'build:error': (error: Error) => HookResult
|
||||||
|
Loading…
Reference in New Issue
Block a user