Nuxt Content not loading with NuxtLink
I am getting started with Nuxt content and have configured and index and slug page to display my blog directory. The problem I am running into is when clicking on the NuxtLink generated on the index page(ex /blog/hello), it goes to the appropriate link but doesn't display anything. If I remove the v-if from the slug, I get the following error via console
If I access the link directly the page renders as expected.
This one has me a little perplexed. Any help is greatly appreciated.
index.vue
slug.vue
3 Replies
Hi @mast3rof0. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Your setup for listing blog posts and rendering individual posts with Nuxt Content is correct and matches the recommended approach in the documentation. The error you’re seeing:
happens because the
- Always guard
<ContentRenderer> component expects a non-null object for its value prop, but sometimes blog is null or undefined when the component renders—especially during client-side navigation with <NuxtLink>. This is a common scenario when using async data fetching.
Why does this happen?
- On initial navigation, useAsyncData is still fetching the data, so blog is null.
- If you remove the v-if="blog", you pass null to <ContentRenderer>, which causes the error.
How to fix it:
- Keep the v-if="blog" on <ContentRenderer> to ensure it only renders when data is available.
- Optionally, add a fallback for loading and not found states.
Example fix for slug.vue:
This approach is also shown in the official docs and ensures you never pass null to <ContentRenderer>, preventing the error and improving the user experience with loading and not found states Docs: ContentRenderer.
Summary:- Always guard
<ContentRenderer> with v-if="blog" to avoid passing null.
- Add loading and not found fallbacks for a better UX.
This pattern is the recommended way to handle async content loading in Nuxt Content apps Docs: Render Content Docs: Implement Document Driven mode.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1369461878622916610> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
based on the feedback from kapa.ai, I added teh following to my slug
This resulted in teh page showing 'Blog post not found' when accessing from NuxtLink
Good news / bad news. Good news is that the issue is resolved. The original problem I was having was on the Cloudflare distribution which. was using Nuxt 3.18. Recently they have updated to 4.0.3. After redeploying, everthing seems to be working as expected