I have a React application with server side rendering. I now have to implement Facebook/Google+ share dialog with og:title and og:image being set dynamically to values returned from the API.
I’m using react-helmet to set my default meta tags, however I have troubles making it work dynamically.
I tried using redux-async-connect to prefetch the result, which resulted in meta tags being rendered (I can see them when I look at the source code), however both Facebook and Google+ ignore them.
Do any of you have experience with making this work?
2
Answers
You can render the app inside document like this:
render(<App/>, document)
while App containing all the html you need.
Essentially, in your
public/index.html
file you want to replace the metadata with an identifiable string:And then on the server, you want to replace these strings with the dynamically generated information. Here is an example route with Node and Express:
Taken from this tutorial here: https://www.kapwing.com/blog/how-to-add-dynamic-meta-tags-server-side-with-create-react-app/