You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to utilize documentDriven to set the head/meta tags for blog pages on my site. However I am experiencing an issue with tags from other pages being retained as I navigate through the site.
Navigate to http://localhost:3000/blog/my-first-blog-post
See the following meta tags as expected:
<metaname="keywords" content="My First Blog Post : keywords"><metaname="robots" content="My First Blog Post : robots"><metaname="author" content="My First Blog Post : author"><metaname="copyright" content="My First Blog Post : copyright"><metaname="description" content="My First Blog Post : description"><metaproperty="og:image" content="/assets/image1.jpg"><metaproperty="og:image:width" content="400"><metaproperty="og:image:height" content="300"><metaproperty="og:image:alt" content="My First Blog Post : img alt">
Navigate back to http://localhost:3000/ (homepage)
Unexpectedly see the following meta tags:
<metaname="keywords" content="My First Blog Post : keywords"><metaname="robots" content="My First Blog Post : robots"><metaname="author" content="My First Blog Post : author"><metaname="copyright" content="My First Blog Post : copyright"><metaproperty="og:image" content="/assets/image1.jpg"><metaproperty="og:image:width" content="400"><metaproperty="og:image:height" content="300"><metaproperty="og:image:alt" content="My First Blog Post : img alt"><metaname="description" content="This is the homepage">
Only description was changed back. Everything else is retained from the blog post, even copyright which is defined in app.vue.
Setup
Here are the relevant parts of my setup. Also avaialble in my repo.
Homepage. Only setting the title and meta.description here.
<scriptsetup>useHead({title: 'Homepage',meta: [{name: 'description',content: 'This is the homepage'}]})</script><template><main><TheHero> A Nuxt Content v2 Blog with Tailwind </TheHero><ArticleContainer><BlogPostList />
</ArticleContainer></main></template>
---
title: "My First Blog Post"description: "My First Blog Post : description"image:
src: "/assets/image1.jpg"alt: "My First Blog Post : img alt"width: 400height: 300head:
meta:
- name: "keywords"content: "My First Blog Post : keywords"
- name: "robots"content: "My First Blog Post : robots"
- name: "author"content: "My First Blog Post : author"
- name: "copyright"content: "My First Blog Post : copyright"
---
Additional information
As a side note, I am getting this console warning as well.
WARN Using <NuxtLayout> inside app.vue will cause unwanted layout shifting in your application.Consider removing <NuxtLayout> from app.vue and using it in your pages.
I'm not sure what to make of this since my app.vue mirrors what is suggested in the docs.
Summary
Longtime programmer but relatively new to Vue/Nuxt. I suspect I'm missing something in my setup or maybe there is a conflict when combining useHead() and documentDriven.
My question for the community is, how would you go about setting up your head/meta tags for the following conditions?
Page-specific head/meta tags that are tied to their pages/routes
Such as my attempt to use useHead() in pages/index.vue.
Global defaults that are used when not defined in a page/route.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am attempting to utilize documentDriven to set the head/meta tags for blog pages on my site. However I am experiencing an issue with tags from other pages being retained as I navigate through the site.
Reproduction
Navigate to
http://localhost:3000/
(homepage)See the following meta tags as expected:
Navigate to
http://localhost:3000/blog/my-first-blog-post
See the following meta tags as expected:
Navigate back to
http://localhost:3000/
(homepage)Unexpectedly see the following meta tags:
Only
description
was changed back. Everything else is retained from the blog post, evencopyright
which is defined inapp.vue
.Setup
Here are the relevant parts of my setup. Also avaialble in my repo.
nuxt.config.ts
Enable documentDriven.
package.json
Use Edge Channel
app.vue
I am trying to set global defaults here.
pages/index.vue
Homepage. Only setting the
title
andmeta.description
here.pages/blog[...slug].vue
Blog catchall route.
content/blog/my-first-blog-post.md
Front matter for blog post.
Additional information
As a side note, I am getting this console warning as well.
I'm not sure what to make of this since my
app.vue
mirrors what is suggested in the docs.Summary
Longtime programmer but relatively new to Vue/Nuxt. I suspect I'm missing something in my setup or maybe there is a conflict when combining
useHead()
anddocumentDriven
.My question for the community is, how would you go about setting up your head/meta tags for the following conditions?
Page-specific head/meta tags that are tied to their pages/routes
Such as my attempt to use
useHead()
inpages/index.vue
.Global defaults that are used when not defined in a page/route.
Such as my attempt to use
useHead()
inapp.vue
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions