Search code examples
htmlvue.jssingle-page-applicationnuxt.jsprerender

How do I get Nuxt.js to pre-render the full HTML for pages?


I have a basic app (nuxt version 2.12.2) that I made by running npx create-nuxt-app, and setting mode to "SPA". When I use npm run build or npm run generate, it creates an HTML file for each page, but it does not pre-render any of the actual HTML in the page. It only has the JavaScript that loads the single-page application. I want each page to have pre-rendered HTML for SEO reasons. What is the best way to do that?

I'm really surprised I haven't found anything in the Nuxt.js documentation that addresses this.


Solution

  • I agree it's a gap in the documentation, I've also struggled with that. As it turns out nuxt generate acts differently with universal and spa modes. If you want your HTML files to be pre-rendered on the server you need universal mode.