onPrerenderStart() hook

The onPrerenderStart() hook is called once when pre-rendering starts. It receives as argument an array of all page contexts to be pre-rendered, and returns a new array of page contexts, giving you a chance to add/remove/modify pages. This is usually used for internationalization.

export { onPrerenderStart }
 
async function onPrerenderStart(prerenderContext) {
  // new page contexts
  const pageContexts = []
 
  // for each original page context:
  prerenderContext.pageContexts.forEach((pageContext) => {
    // for each locale, push a new page context to pageContexts
    // ...
  })
 
  return {
    prerenderContext: {
      pageContexts
    }
  }
}

TypeScript

export { onPrerenderStart }
 
import type { OnPrerenderStartAsync, PageContextServer } from 'vike/types'
 
const onPrerenderStart: OnPrerenderStartAsync = async (
  prerenderContext
): ReturnType<OnPrerenderStartAsync> => {
  // ...
}

Don't omit ReturnType<OnPrerenderStartAsync> otherwise TypeScript won't strictly check the return type.

See API > pageContext > Typescript for more information on how to extend pageContext with your own extra properties.