Closed gduteaud closed 1 month ago
I was able to resolve this as follows.
const serializers = {
marks: {
link: (props, children) => {
return h(SanityLink, {
internal: props.slug, // Pass individual props
external: props.external
}, children.slots); // Pass children slots
},
},
}
SanityLink.vue:
<template>
<!-- Use NuxtLink for internal links, 'a' tag for external links -->
<NuxtLink v-if="internal" :to="`/blog/${internal}`">
<slot />
</NuxtLink>
<a v-else :href="external">
<slot />
</a>
</template>
<script setup>
// Props to define whether the link is internal or external
const { internal, external } = defineProps({
internal: String, // For internal links
external: String, // For external links
});
</script>
Hi all,
I am struggling to correctly render portable text internal and external links in Nuxt. I'm not sure which part of my setup is the issue. When I look at the result of my query I can see all the information that should be needed to render internal and external links correctly but I'm unable to get it to actually work.
I'm thinking the way I've defined internal and external links in my schema might be at the root of the problem, but I would really like to find a solution that supports this structure.
Any guidance is appreciated, thank you!
Here is my query:
Serializers:
Usage:
My SanityLink component:
And finally my blockContent type schema type: