If you don't use vike-react
/vike-vue
/vike-solid
, then you have direct control over <head>
tags in your onRenderHtml()
hook.
If you use vike-react
/vike-vue
/vike-solid
, then see Guides > <head>
tags.
By page
To define <head>
tags on page-by-page basis, we recommend creating new settings, for example title
and description
as shown at API > meta
> Example: title
and description
.
By component
To define <head>
tags by any UI component:
- Add
'headProps'
to passToClient
.
- Use
usePageContext()
so that pageContext.headProps
can be accessed and modified by any component.
For example:
Client Routing
If you use Client Routing, make sure to update document.title
upon page navigation:
Libraries
You can also use libraries such as @vueuse/head or react-helmet.
But we recommend using such library only if you have a rationale as the aforementioned solutions are simpler.
Head libraries already sanitize the HTML <head>
, this means you can skip escapeInject
and wrap the overall result with dangerouslySkipEscape()
.