harlan-zw / nuxt-seo

The complete SEO solution for Nuxt.
https://nuxtseo.com
MIT License
1.08k stars 70 forks source link

definePageMeta > breadcrumb not accepting dynamic values #324

Open richgcook opened 1 month ago

richgcook commented 1 month ago

Details

Being able to override specific page labels in the breadcrumb using definePageMeta is great but I'm unable to use dynamic values consistently in definePageMeta even though it works in useHead without problems but randomly, not all the time, I get a 500 server error title is not defined

An extract of my code below to demonstrate the setup but is there any reason why using title.value, which works consistently in useHead, would error out when used in definePageMeta?

<script setup>

...

const { data } = await useSanityQuery(query)

const { title, description, image, bodyClass } = useMetaBodyHelpers(data?.value.issuesPage)

useHead({
    title: title.value,
})

definePageMeta({
    breadcrumb: {
        label: title.value,
    },
})

</script>
harlan-zw commented 1 month ago

Hi, definePageMeta only supports static values as it's a compile-time macro. You can learn more here: https://nuxt.com/docs/api/utils/define-page-meta

You should follow the docs for overrides to use dynamic data.

mavrick commented 1 month ago

@harlan-zw are you able to provide an example of usage, i'm running into a simialr issue and using useBreadcrumbItems({ overrides: [] }); in setup() or created() has no affect

mavrick commented 1 month ago

@harlan-zw are you able to provide an example of usage, i'm running into a simialr issue and using useBreadcrumbItems({ overrides: [] }); in setup() or created() has no affect

I think i've answered my own question, but there is no global way to affect the usage of useBreadcrumbItems() before the page renders afaik.

harlan-zw commented 1 month ago

If you're able to make a reproduction of the issue I'll be able to provide a solution for you

mavrick commented 1 month ago

https://github.com/mavrick/nuxt-seo-test

folder structure: /pages/[gameId]/events/[eventId]/

http://localhost:3000/cs/events/test/

[
  {
    "to": "/",
    "label": "Home",
    "ariaLabel": "Home",
    "current": false
  },
  {
    "to": "/cs",
    "label": "Counter Strike",
    "ariaLabel": "Counter Strike",
    "current": false
  },
  {
    "to": "/cs/events",
    "label": "Gameid Events Eventid",
    "ariaLabel": "Gameid Events Eventid",
    "current": false
  },
  {
    "to": "/cs/events/test",
    "label": "Gameid Events Eventid",
    "ariaLabel": "Gameid Events Eventid",
    "current": true
  }
]

"@nuxtjs/seo": "2.0.0-rc.23",