passToClient
Most pageContext
values are available only on the server-side, but you can use passToClient
to make values available on the client-side.
Some values, such as pageContext.data
, are already passed to the client-side by default.
Error
If you try to access a pageContext
value that isn't defined on the client-side then Vike throws an error:
[Vike][Wrong Usage] pageContext.someProp isn't defined on the client-side
You can look at the stack trace to find the
pageContext.someProp
occurrence in your code that triggers the error.
To avoid the error:
- add
'someProp'
topassToClient
(see above), or - replace
pageContext.someProp
with'someProp' in pageContext && pageContext.someProp
.
Default
When using Client Routing, the following are also available on the client-side by default:
pageContext.Page
pageContext.data
pageContext.config
pageContext.isHydration
pageContext.isBackwardNavigation
pageContext.routeParams
pageContext.urlOriginal
pageContext.urlPathname
pageContext.urlParsed
When using Server Routing, the following are also available on the client-side by default:
pageContext.Page
pageContext.data
pageContext.config
pageContext.routeParams
Serialization
Serialization is done with @brillout/json-serializer
.
User-defined classes are lost during serialization:
See GitHub > brillout/json-serializer
> #3 Support user-defined classes.