-
Notifications
You must be signed in to change notification settings - Fork 48
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
The prismic nuxt tutorial/guide has a sample html serializer that includes nuxt-link. This isn't getting transformed into an actual link #60
Comments
i have exact same problem. Have you fixed it? |
@KristianJohansenVakwerk I placed a little hack in to make it work. Change Then in your code (probably in Obviously the above is a bit of pseudo code. If you can't figure it out let me know and tomorrow or Friday I'll copy/paste what I did. |
Thanks very much that worked. |
You can also use the html serializer directly provided by prismic for nuxt. This one uses the nuxt-link tag:
Source: Using Prismic with Nuxt.js |
@itpropro it's the same one. If you see the link I included at the very top of the post, it's the exact same link you included at the bottom of yours. |
Hi @adrianocr Thank you for the bug report, indeed since we don't use the Vue runtime compiler since it does not support SSR, the Instead, the way to go is to do something like you did, I suggest to add a property like if (element.data.link_type === 'Document') {
result = `<a href="${url}" data-nuxt-link>${content}</a>`
} else {
const target = element.data.target ? `target="'${element.data.target}'" rel="noopener"` : ''
result = `<a href="${url}" ${target}>${content}</a>`
} Then you can add your listeners based on the You can use a mixin to share it across your components (until we find something better for it). |
Thank you for your input @atinux! This thread has been very helpful for me. Rather than using a mixin to do this at the component level, I found it more useful to wrap this solution into a clientside plugin that will handle it for all cases globally. The full solution becomes:
export default async ({ redirect }) => {
window.addEventListener(
'click',
(event) => {
// If the clicked element doesn't have the right selector, bail
if (!event.target.matches('a[data-nuxt-link]')) return
// Don't follow the link
event.preventDefault()
// Push link destination to router
redirect(event.target.pathname)
},
false
)
}
{
// ...other configuration
plugins: [
// ...other plugins
{ src: '~/plugins/prismicLinks', ssr: false }
]
} For anyone that finds this useful, I've put a more full example including the htmlSerializer code here: https://gist.github.com/johndigital/21b04f00abca2dca35595289fd51e680 |
To add more context, you can also use this module https://github.com/daliborgogic/nuxt-interpolation |
@johndigital's solution worked for me! |
@johndigital 's answer was extremely helpful! I ran into a situation where I needed to account for query strings and hashes and ended up switching
to
which solves the issue on my end. |
I guess maybe this can be documented @lihbr ? |
I'll have a look into this yup + looking forward to fix that with next major of our Vue kit |
Looking forward to native support for it 🔥 |
If you go over to https://prismic.io/docs/vuejs/getting-started/prismic-nuxt you'll see that they have the following sample serializer:
Which I have placed in /app/prismic/html-serializer.js
This works perfectly except
<nuxt-link>
. It doesn't get transformed/rendered. If I convert it to a standarda
tag it works fine, but obviously without handling links internally by the router. So is there a way to get this to work? I have also tried and but neither work.The text was updated successfully, but these errors were encountered: