Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

HeadContent.tsx

25 lines946 Bytes

1import { MetaProvider } from '@solidjs/meta'
2import { For } from 'solid-js'
3import { Asset } from './Asset'
4import { useTags } from './headContentUtils'
5import type { AssetCrossOriginConfig } from '@tanstack/router-core'
6​
7export interface HeadContentProps {
8 assetCrossOrigin?: AssetCrossOriginConfig
9}
10​
11/**
12 * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
13 * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`
14 * to ensure it's part of the reactive tree and updates correctly during client-side navigation.
15 * The component uses portals internally to render content into the `<head>` element.
16 */
17export function HeadContent(props: HeadContentProps) {
18 const tags = useTags(props.assetCrossOrigin)
19​
20 return (
21 <MetaProvider>
22 <For each={tags()}>{(tag) => <Asset {...tag} />}</For>
23 </MetaProvider>
24 )