nuxt: Dynamic OG/meta tags do not work anymore
Versions
- nuxt: V2.14, V2.15.3
- node: 15.3, 17.5.0
Reproduction
~~https://developers.facebook.com/tools/debug/?q=https%3A%2F%2Ft0f1k.sse.codesandbox.io~~
Steps to reproduce
Simplest example is to use Facebook developer tools to reproduce. I tried it on the sample code of the tutorial page It shows that the example code does not behave as the tutorial suggests. The same behaviour is noticeable in other uses (e.g. with i18n-module).
Step by step with screenshots if further down below https://github.com/nuxt/nuxt.js/issues/10318#issuecomment-1062060394
What is Expected?
To show a dynamic title or other meta information depending on what is set in the head() of each page.
What is actually happening?
The fixed value defined in nuxt.config.js is used, not the dynamic title value set in head() function. Apparently this is because FB or any OG implementation I tested (Whatsapp, Signal, etc.) does not execute JS.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 31 (6 by maintainers)
Hi @danielroe, I have the same issue after upgrading Nuxt from 2.8 to latest version 2.15.7. I have an app with SSR mode and now all my pages have the default title and description set in the
nuxt.config.jsfile. The data provided in all other pages, inside thehead, are totally ignored and I don’t know anymore what to do.The steps to reproduce are very simple:
nuxt.config.js.Things you will notice:
I did nothing fancy. I think this version has a serious bug around the
headand it would be nice to know a solution… I’m not loading components automatically, I never did it. And myheadis inside Pages only.Also, I tried using another plugin called
nuxt-seoand it has the same issue. So, for sure it is something with Nuxt.Thanks!
I’ve taken a look, and you’re quite right; this is the case. It seems to be caused by using
head()within a component that is auto-imported by@nuxt/components. So, for now, a workaround is to explicitly import the child component:I don’t use any components and only have an index page and a dynamic page.
I am having the same issue with ssr:false and target:static. My hosting environment does not support running the app on the server as it needs to be a static site within Tomcat. Page source and Inspect Elements have two diff meta tags.
I have the same issue.
ssr: true,target: staticis set in thenuxt.config.js. OG/meta tags work for non-dynamic routes, but does not work for dynamic routes.asyncDatais used to prefetch data from the API to populatemetainsideheadmethod.nuxtversion is2.15.5. Production site is running on Laravel Forge, am I doing something wrong or missing something in the configuration?@danielroe I did not mean to offend you, however the way you replied made me feel as if my issue was not read properly. Believe me when I say I spend a lot of hours examining the problem for possible causes and doing my due diligence before opening an issue with you guys. What you created and maintain is an amazing tool, and much appreciated, I am sorry if I did not make that clear in the way it was phrased above.
I’ve reopened the issue to remind me to have a look at this at some point in the future.
The kind of information you’ve now provided was exactly what I was asking for earlier. Thanks for providing it.
Note that the URL I tested was the one you provided in your original issue.
Please consider treating other people, particularly those who are helping you, with more consideration.
My code is actually irrelevant to the issue, as the source code of the tutorial page already shows exactly that it is not working. Therefore representing a reproducible example without the possibility of human error on my end, which is much superior imho.
Want to share my experience. Had exactly the same issue as described here. Spend 2 full days investigating and trying out different stuff to no avail.
In my case the issue was I had a
v-ifdirective on a div that wrapped<nuxt>, waiting for some local storage data. That essentially deactivated SSR. Once I’ve removed thatv-ifeverything worked as expected.I have the same issue but not for a component but for a dynamic sub-page, e.g.
_slug.vue.I am not sure if my problem was exact same as mentioned in this issue, but I did manage to find a solution which was simply running nuxt app in
ssrmode. It makes sense that meta tags won’t work with dynamic routes when app is served as static HTML becausenuxt generatecan only pre-generate already defined routes. I was usingmetamethod which would set meta tags with the data returned fromasyncData. So the solution was updatingnuxt.config.js, changingssrtotrueandtargettoserver, usingpm2to runnuxt'snodeserver and usinglaravelas a API backend.