[Vuejs]-Use dynamic routes in Nuxt SPA after generating

0👍

If you are using SPA mode, you don’t really need to worry about dynamic routes, as everything is rendered on the client. The only thing you would need to take care of, is setting up your production server to always redirect to your index.html, so you don’t get a 404 when accessing other pages.


If you are using Universal you could still generate a SPA fallback for handling your dynamic routes on the client side, by adding this to your nuxt.config.js:

Docs

generate: {
  fallback: true,
  // ...
},

Using this, Nuxt generates a 404.html which will render the page in SPA mode, instead of showing a 404, while the other routes are generated like normal.

If you want to properly generate all routes and have instant access, you could use this technique to show users a temporary SPA version of your page, until the page is rebuilt.

Leave a comment