Edit this page
Hooks
List of built-in hooks. (You can create your own.)
Basic
data()
: server (configurable) Called before the page is rendered, for fetching data.guard()
: server (configurable) Protect pages from unprivileged access.onHydrationEnd()
: client Called after the page is hydrated.onPageTransitionStart()
: client Called upon page navigation, before the new page starts rendering.onPageTransitionEnd()
: client Called upon page navigation, after the new page has finished rendering.onBeforePrerenderStart()
: server Called before the whole pre-rendering process starts.onPrerenderStart()
: server Global hook called when pre-rendering starts.onCreateApp()
: server & clientvike-vue
Called after creating Vue'sapp
instance.
Advanced
Most users don't need to know about these hooks.
onBeforeRender()
: server (configurable) Called before the page is rendered, lower-level and usually for advanced integrations with data fetching tools.onRenderHtml()
: server Called when a page is rendered to HTML on the server-side.onRenderClient()
: client Called when a page is rendered on the client-side.onBeforeRoute()
: server & client Called before the URL is routed to a page.onBeforeRenderClient()
: client Called at the beginning ofonRenderClient()
.onAfterRenderClient()
: client Called at the end ofonRenderClient()
.onBeforeRenderHtml()
: server Called at the beginning ofonRenderHtml()
.onAfterRenderHtml()
: server Called at the end ofonRenderHtml()
.
Upcoming
Potentially upcoming hooks:
- New hook
onBoot()
- New hook
onRequestBegin()
- New hook
onLog()
- New hook
onRenderContent()
: generate non-HTML files with arbitrary content
Order
The order in which the hooks are called.
The following doesn't contain the hooks of the Vike extensions
vike-react
/vike-vue
/vike-solid
such asonAfterRenderHtml()
oronAfterRenderClient()
.
Default
If you didn't change the environment of data()
nor onBeforeRender()
:
First render
-
server
renderPage()
-
server
onBeforeRoute()
-
server
Routing
The routing executes your Route Functions (of all your pages).
-
server
guard()
-
server
data()
-
server
onBeforeRender()
-
server
onRenderHtml()
-
client
onRenderClient()
-
client
onHydrationEnd()
Page navigation
-
client
onPageTransitionStart()
-
client
onBeforeRoute()
- client Routing
-
server
onBeforeRoute()
-
server
Routing
The routing is executed twice: once for the client and once for the server.
-
server
guard()
-
server
data()
-
server
onBeforeRender()
-
client
onRenderClient()
-
client
onPageTransitionEnd()
Client-side only data()
If you configured data()
and onBeforeRender()
as well to run only on the client-side:
First render
-
server
renderPage()
-
server
onBeforeRoute()
-
server
Routing
The routing executes your Route Functions (of all your pages).
-
server
onRenderHtml()
-
client
guard()
-
client
data()
-
client
onBeforeRender()
-
client
onRenderClient()
-
client
onHydrationEnd()
Page navigation
-
client
onPageTransitionStart()
-
client
onBeforeRoute()
- client Routing
-
client
guard()
-
client
data()
-
client
onBeforeRender()
-
client
onRenderClient()
-
client
onPageTransitionEnd()