Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with useServerHead or useHead with Vue 2.7 + Vite + Vue Router #187

Closed
antsteyeragorize opened this issue Apr 26, 2023 · 3 comments
Closed

Comments

@antsteyeragorize
Copy link

antsteyeragorize commented Apr 26, 2023

Hello ! Hope you're doing well.

I'm trying to setup a SSR POC with Vue 2.7, Vite and Vue router in order to migrate a big business app from Webpack to Vite.

I have a weird behavior when using useServerHead or useHead and vue router. I don't know what's the issue here, but after the first call to the server, the meta seems to be lost. It only works on first page called.

Here the codesandbox.

Don't hesitate to check the README for the step to reproduce.

@antsteyeragorize antsteyeragorize changed the title Issue with useServerHead with Vue 2.7 + Vite + Vue Router Issue with useServerHead or useHead with Vue 2.7 + Vite + Vue Router Apr 26, 2023
@Remzi1993
Copy link

@harlan-zw Is still an issue?

@greetfish
Copy link

greetfish commented Jun 29, 2023

I also meet this issue in NUXT 3.5

const nuxtApp = useNuxtApp();
const route = useRoute();
const merchandise = ref({
  localImage: {},
  richArray: [],
});
await useAsyncData(() =>
  $fetch('/api/public/get_detailPage', {
    method: 'post',
    body: { locale: locale.value, id: route.params.id, pageType: 10 },
    onResponse({ response }) {
      if (response._data.code === 200) {
        merchandise.value = response._data.data;
        console.log(merchandise.value);
        gltf.value = merchandise.value.d3;
      }
    },
  })
);

useHead({
  title: merchandise.value.title,
  meta: [
    { name: 'description', content: merchandise.value.keyword },
    { name: 'title', content: merchandise.value.title },
  ],
  link: [
    {
      rel: 'canonical',
      href: siteUrl() + (locale.value === 'en-us' ? '' : '/' + locale.value + '/products/' + merchandise.value.id),
    },
  ],
  script: [
    {
      type: 'application/ld+json',
      innerHTML:
        '{' +
        '"@context": "http://schema.org",' +
        '"@type": "BreadcrumbList",' +
        '"itemListElement":[' +
        '{' +
        '"@type": "ListItem",' +
        '"position": 1,' +
        '"item": {' +
        '"name": "首页",' +
        '"@id": "' +
        siteUrl() +
        (locale.value === 'en-us' ? '' : '/' + locale.value) +
        '"' +
        '}' +
        '},' +
        '{' +
        '"@type": "ListItem",' +
        '"position": 2,' +
        '"item": {' +
        '"name": "' +
        nuxtApp.$i18n.t('news.news') +
        '",' +
        '"@id": "' +
        siteUrl() +
        (locale.value === 'en-us' ? '' : '/' + locale.value + '/news') +
        '"' +
        '}' +
        '}' +
        ']' +
        '}',
    },
  ],
});

after first request from server,it gos well.
image

a seconds later,it shows undefine.
image

@harlan-zw harlan-zw closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2023
@greetfish
Copy link

greetfish commented Sep 13, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants