Head Tags
You’ll often need to add tags to your app’s <head>
section. There are three ways to do this: using the Helmet library, using the <Components.HeadTags/>
component, or using the Head
object.
Helmet
You can use Helmet inside a VulcanJS app just like inside any other React app:
1 | const Layout = ({children}) => |
Components.HeadTags
Using HeadTags
Out of the box, a VulcanJS app adds a few default tags such as <title/>
, <meta name='description'/>
, etc. These are all added using Helmet by Components.HeadTags
(called from inside the App
component), using values provided by your settings.json
file.
In some cases, you’ll want to change these values for a given page. For example, a single post page will want to have a different title than your homepage. You can do that by calling Components.HeadTags
directly anywhere inside your component tree with one or more of the following props:
title
url
image
description
1 | <Components.HeadTags url={Posts.getPageUrl(post, true)} title={post.title} image={post.thumbnailUrl} description={post.excerpt} /> |
By calling HeadTags
again, you’ll be calling Helmet again, which in turn will override the head tags previously set by the App
component.
Overriding Headtags
Since Components.HeadTags
is a component, you can also override it completely using replaceComponent('HeadTags', MyComponent)
.
The Head Object
Finally, there are also some cases where you want to add or remove a tag from outside your React components. You can do so using the Head
object.
For example. here is how the vulcan:rss
package adds an RSS feed link to the head:
1 | import { Head, Utils } from 'meteor/vulcan:core'; |
You can also remove a tag using removeFromHeadTags
:
1 | import { removeFromHeadTags } from 'meteor/vulcan:core'; |
Head Components
You can also use the Head
object to add React components to every page of your app (this can be useful for adding analytics integrations wrapped inside React components, for example). Just push the components to Head.components
.
If you push an array (such as [myComponent, withCurrentUser]
) the array will be interpreted as a component + HoC array similar to the arguments of registerComponent
.