Hooks
tags:resolve Hook
On this page
The tags:resolve hook runs after tags:beforeResolve and before tags:afterResolve. Built-in plugins use it for transformations such as canonical URL resolution, alias-based sorting, and template-parameter substitution.
Core deduplication has already happened before this hook runs.
Hook Signature
export interface Hook {
'tags:resolve': (ctx: TagResolveContext) => SyncHookResult
}
interface TagResolveContext {
tagMap: Map<string, HeadTag>
tags: HeadTag[]
}
This hook is synchronous. Change ctx.tags when adding, removing, or reordering members of the resolved set. Use tagMap for identity lookups; use ctx.tags to iterate because arrayable meta groups can be represented by an aggregate map value at runtime.
Usage Example
import { defineHeadPlugin } from 'unhead/plugins'
export const absoluteImagePlugin = defineHeadPlugin({
key: 'absolute-images',
hooks: {
'tags:resolve': ({ tags }) => {
for (const tag of tags) {
const key = tag.props.property || tag.props.name
if (tag.tag === 'meta' && (key === 'og:image' || key === 'twitter:image'))
tag.props.content = new URL(tag.props.content, 'https://example.com').href
}
}
}
})
For canonical URL handling, prefer the built-in CanonicalPlugin.
Did this page help you?
On this page