These options are implemented by the UI framework Vike extension (vike-react/vike-vue/vike-solid). See Without Vike extension if you don't use such extension.
Head
To add <head> tags to all your pages:
// /pages/+Head.jsx or// /pages/+Head.vue// Environment: serverexport { Head }import socialImage from '../assets/images/socialImage.jpg'import favicon from '../assets/images/favicon.png'function Head() { return <> <meta charset="utf-8"> <title>SpaceX</title> <meta name="description" content="We deliver payload to space."> <meta property="og:image" content={socialImage}> <link rel="icon" href={favicon}> <meta name="viewport" content="width=device-width, initial-scale=1"> </>}
While defining <title> by using the Head setting correctly sets the page's title for the first page the user visits, it doesn't update the page's title upon client-side navigation.
Most <head> tags, such as the social image tag <meta property="og:image">, don't need to be updated upon client-side navigation because they are only used by crawlers. (Browsers don't do anything with <meta property="og:image">.) Crawlers don't execute JavaScript and, therefore, don't client-side navigate.
Likewise, if your favicon can change from page to page, then define /pages/rocket/starship/+favicon.png instead of using the Head setting.
You can set title and favicon based on fetched data, for example:
// With TypeScript:import type { Data } from './+data'import type { PageContext } from 'vike/types'export function title(pageContext: PageContext<Data>) { const rocket = pageContext.data return rocket.title}
As shown here you can define the logic, of using data.title to set the page's title, once and apply it to all your pages.
useHead()
The upcoming useHead() component hook will enable any UI component to add <head> tags, see: New component hook useHead().
Internationalization
Example of internationalizing (i18n) <head> tags:
// /pages/+Head.js// Environment: serverexport { Head }import { usePageContext } from 'vike-react/usePageContext' // or 'vike-vue' / 'vike-solid'function Head() { const pageContext = usePageContext() const description = pageContext.locale === 'de-DE' ? 'Wir liefern zum Weltall.' : 'We deliver payload to space.' return <> <meta name="description" content={description}> </>}
// /pages/+title.js// Environment: server, clientexport function title(pageContext) { const title = pageContext.locale === 'de-DE' ? 'SpaceX | Das Weltall Unternehmen' : 'SpaceX | The space company' return title}