Hi guys, I’ve a little issue with generating custom meta tags on multiple pages. So, long story short, I’ve multiple pages where I’ve set the <MetaTags ... />
component in order to customize the title and other OG elements. I’ve also set the ‘prerender
’ tag (inside the web/src/Routes.tsx
file) to make it works, cause otherwise the meta tags will be generated on client side (CSR), thus they won’t work when you share a link on some social network or app (to test them I’ve used www.opengraph.xyz).
Now, the real issue is the fact that those pre-rendered meta tags are not correctly generated, since they are all the same for every page (to be more precise they are the same as the ones present inside the last page specified between the prerender
tag in the Routes.tsx
file).
I’ve tried a few things like:
- Upgrade/Downgrade the RW version of the project
- Using the ‘
Head
’ component instead of the ‘MetaTags
’
But sadly the problem persists. To be honest I’ve also rapidly checked the RW source code (especially the prerenderHandler.js
and runPrerender.tsx
files), but I couldn’t find where it might be the issue.
So guys, have you some sort of workaround or fix for this?
PS. Another small issue that I’ve experienced was that if you prerender also the ‘NotFoundPage
’ , RW will throw some console error.
Minimal setup to reproduce the issue
-
Create a RW project:
yarn create redwood-app test
-
Generate at least 2 pages:
yarn rw g page Home yarn rw g page About
-
Edit the
web/src/Routes.tsx
file by adding the ‘prerender
’ tag for the generated pages like so:<Router> <Set prerender> <Route path="/about" page={AboutPage} name="about" /> <Route path="/home" page={HomePage} name="home" /> </Set> <Route notfound page={NotFoundPage} /> </Router>
-
Run ‘
yarn rw build web
’ and check the OG meta tags inside the files:web/dist/about.html
web/dist/home.html
You will notice that the
AboutPage
has the same tags of theHomePage
(i.e. they are the same of the last specified page inside theprerender
tag).
Environment
Just to give you the full picture I’m currently using:
- Redwoodjs/core:
3.0.0
- Node:
16.14.0
- Yarn:
3.2.3
- System:
macOS Big Sur 11.6.4