Gatsby: Parsing HTML and converting anchors to gatsby Link component

Created on 26 Jun 2019  路  1Comment  路  Source: gatsbyjs/gatsby

I currently run a GatsbyJS website that fetches 300 Wordpress posts using gatsby-source-wordpress, despite the fact that media cannot be fetched and it freezes all the time in source and transform node, the contents are getting in easily.

But the issue is that there are links in those posts, and they are in original html anchor tag, which means if some one clicks on them, it's gonna refresh the page, calling for all the react libraries and stuff again and everything goes back to 5 years ago :P. It's almost as if we are not using the magic of virtual DOM at all.

I was looking for a way to scan for all these anchor tags and convert them to Gatsby Link component. I've tried React-HTML-Parser, and tried googling and researching on the internet.

I couldn't find a legitimate way to get this down. Please illuminate me on this matter.

Most helpful comment

If I understood you correctly, it looks like this https://www.gatsbyjs.org/packages/gatsby-plugin-catch-links/ plugin should do what you want to achieve.

Hopefully this helps! 馃檪

>All comments

If I understood you correctly, it looks like this https://www.gatsbyjs.org/packages/gatsby-plugin-catch-links/ plugin should do what you want to achieve.

Hopefully this helps! 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

theduke picture theduke  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

signalwerk picture signalwerk  路  3Comments