Document API allows you to set page titles, meta tags, and other head elements both during server-side rendering and on the client.
Document Component
TheDocument component is the foundation for managing your app’s HTML structure and metadata:
title- Page title (sets<title>tag)lang- Language attribute on<html>elementbase- Base URL for relative linkscharset- Character encoding (default: ‘utf-8’)viewport- Viewport meta tagmeta- Additional meta tagsstyles- Global CSS style ruleshead- Additional components in<head>body- The main app component
Dynamic Meta Tags
UseDocument.head() anywhere in your component tree to set metadata:
Meta Tag Override Rules
Meta tags are merged using the following system:- Elements with an
idoverride other elements with the sameid <title>elements override other<title>elements<base>elements override other<base>elements<meta>elements override other<meta>elements with the samename
Open Graph Tags
Optimize for social media sharing:Twitter Card Tags
Optimize for Twitter:summary- Default cardsummary_large_image- Large image cardapp- App installation cardplayer- Video/audio player card
Canonical URLs
Set canonical URLs to avoid duplicate content penalties:Structured Data (JSON-LD)
Add structured data for rich search results:Favicon and Icons
Add favicons and app icons:HTML and Body Attributes
Set attributes on<html> and <body> elements:
Route-Specific SEO
Combine with routing for page-specific SEO:Robots Meta Tag
Control search engine crawling:Complete SEO Example
Best Practices
Unique titles and descriptions
Unique titles and descriptions
Each page should have a unique title and meta description:
- Title: 50-60 characters
- Description: 150-160 characters
Use PreloadStateMixin for dynamic content
Use PreloadStateMixin for dynamic content
Fetch SEO-critical data during SSR:
Include Open Graph images
Include Open Graph images
Always provide og:image for better social sharing:
- Recommended size: 1200x630 pixels
- Format: JPG or PNG
- Size: < 5MB
Test with validation tools
Test with validation tools
Validate your meta tags:
Related
Routing
Set page titles in routes
Data Fetching
Preload data for SEO
Server Rendering
Enable SSR for better SEO