oedotme / generouted

Generated file-based routes for Vite
https://stackblitz.com/github.com/oedotme/generouted/tree/main/explorer
MIT License
1.02k stars 47 forks source link

Question about how to do SEO on a per page basis. #164

Closed samhren closed 4 months ago

samhren commented 4 months ago

How would I use custom meta tags on a per page basis with generouted? As of right now I can use react-helmet to do it dynamically, but this loads after the SEO is already generated. Is there any way I can add tags to the HTML, hardcoded? Thanks.

oedotme commented 4 months ago

@samhren Vite supports SSR and you could do pre-rendering in order to generate the content of the pages with the meta tags included. Here's Vite's official docs for pre-rendering and (Static Site Generation) SSG.

The main thing you'd need from generouted is the routes object/array to create a StaticRouter, in this step you could also setup the meta tags for SSR.

With an SSR entry in place, you could either use SSR or SSG by running a script to generate full HTML versions for all routes to be served statically.

There was a setup at Render a50fc66 for pre-rending before it was removed. You can refer to the server.ts setup and the prerender.ts script. You'll likely need to change couple of things for the router new APIs and also your usage.

Hope that helps!