V1 Design Migration
Despite being a simple change, the V1 design introduces new foundational capabilities. If you're curious: Why the V1 design?
The overall architecture stays the same: the V1 design is mostly about replacing .page.js
files with so-called plus files: +Page.js
, +route.js
, +onBeforeRender.js
, ...
The migration is straightforward and usually quick to implement. We encourage you to migrate sooner rather than later.
Don't hesitate to reach out if you run into any issue.
The old design is still supported but we recommend to migrate as the docs now showcase the V1 design.
Main migration
Make sure to update Vike to its latest version.
You need to either fully use the V1 design, or fully use the old design. You cannot mix both.
Most of the migration boils down to the following two steps.
1. Migrate /renderer/*.page.*
Move your renderer/
hooks to +
files:
If you've defined a global onBeforeRender()
hook and/or passToClient
:
See API > Config Files for more information about what
+
and.h.js
means.
The suffixes such as
.page.server.js
and.page.client.js
don't exist anymore. After the feature request #744 is implemented, you'll be able to use.server.js
and.client.js
suffixes again but note that they'll serve another purpose.
Move /renderer/
configurations to /renderer/+config.ts
:
Move your error page (if you defined one):
2. Migrate /pages/**/*.page.*
Each page now lives in its own directory.
Apply following additional steps if you've defined:
- Renamed hooks
- Custom hooks/exports
onBeforeRender
in.page.js
(instead of.page.server.js
)- Client init code
If you have many
/pages/**/*.page.js
files then see Migration scripts.
Examples
All official examples have been migrated, see examples/*
.
Notable migrations:
- Basic apps:
onBeforeRender()
hook:- Defined by page in
pages/
: - Defined globally in
renderer/
:
- Defined by page in
- Pre-rendered app (that uses
prerender()
hooks): - Custom exports to custom configs (see migration explanation at Custom hooks/exports):
pageContext.exports.documentProps
->pageContext.config.title
:pageContext.exports.Layout
->pageContext.config.Layout
:pageContext.exports.preloadStrategy
->pageContext.config.preloadStrategy
:
- i18n (pre-rendered) app (that uses hooks
onBeforeRoute()
,onBeforePrerender()
,prerender()
): - Domain-driven file structure (that uses
filesystemRoutingRoot
)
Migration scripts
- Basic starting point: v1-design-migration.js
PR welcome to add your migration script.
Renamed hooks
Old name | New name |
---|---|
render() in .page.client.js | onRenderClient() |
render() in .page.server.js | onRenderHtml() |
prerender() | onBeforePrerenderStart() |
onBeforePrerender() | onPrerenderStart() |
The hooks are equivalent: they just have a new name.
Also note that doNotPrerender
has been renamed:
Old name | New name |
---|---|
doNotPrerender: true | prerender: false |
Custom hooks/exports
If you use custom hooks/exports, then replace them with custom hooks/settings.
You can create your own hooks and settings by using meta
:
See:
onBeforeRender
in .page.js
If you've defined onBeforeRender()
hooks in .page.js
(instead of .page.server.js
):
For convenience, you can use meta
in order to
create a new config dataIsomorph: boolean
for a
page-per-page toggle.
Client init code
The new config client
allows you to define client-side initialization code.
You can also keep using
onHydrationEnd()
.