The link to the dynamic page [kunstwerke] renders fine in the frontend but if I click it I get an error in the chrome console. If I open it in a new tab it loads with no problem. The error when I click relates to the new site:
[kunstwerke].vue:9 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'titel')
On the dynamic site [kunstwerke] there is a title that also uses prismic data. It seems like the is not fully run when I click on the [kunstwerke] link?
The [kunstwerke] dynamic site is set up like this:
The error seems to relate to the prismic data as it doesn't seem to able to load it. What am I missing here? If I link manually to one of the [kunstwerke] page or open the NuxtLink in a new tab it works.
Any ideas?
edit: Also if I use just a normal a-tag and not NuxtLink it works fine?
Thanks @jake I'm trying this right now. I have two problems though:
In nuxt.config.ts I get an error if I want to add the apiOptions:
export default defineNuxtConfig({
modules: ['@nuxtjs/prismic'],
prismic: {
endpoint: 'portolio-feierabend',
apiOptions: {
// example resolving documents with type `page` to `/:uid`
routes: [
{
type: 'homepage',
path: '/'
}
]
}
},
css: ["~/assets/css/styles.css"]
})
If I leave out defineNuxtConfig I don't get that error. Type '{ endpoint: string; apiOptions: { routes: { type: string; path: string; }[]; }; }' is not assignable to type 'Partial<PrismicModuleOptions>'.\n Object literal may only specify known properties, and 'apiOptions' does not exist in type 'Partial<PrismicModuleOptions>'.",
If I use PrismicLink I never get a clickable link. There is no href. I try it like this:
<div v-for="werk in werke" :key="werk.uid">
<PrismicLink :field="werk">test</PrismicLink>
</div>
Thanks that worked to show the correct and clickable links. Unfortunately Now I'm still having the same problem from my original question. The link only open in a new tab. With a click I still get the same error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'titel')
Which chrome says is happening on the dynamic page. They only don't work with these links though. Normally it works fine. Could there be a problem with loading the same data on a component and a page it links to? Or is it somehow a problem that I create these dynamic pages with the route.params.uid?
Thanks again @jake. I know, Typescript is something to learn soon. But while your suggestion removed the error and the pages load, the prismic data in the v-if="page" statement still doesn't. It only appears after a page refresh. I'm not entirely sure why it is not updating. I tried it with a v-else loading div, but then it's only that div forever.
edit:
I dug a bit deeper and it seems that useAsyncData loads all pages of the type "werk" when I open the page through the prismicLink. It is like "name" is not read at that point. After reload the right data is loaded. I'll try to figure out how I can fix that.