Home > Mobile >  How SSG works in Nuxt?
How SSG works in Nuxt?

Time:11-20

I am new to the Nuxt development platform, having worked mostly in Vue(v2).

Having delved into the docs and experimenting locally for a bit there are a few things I still require clarity on:

  1. In static generation mode, does each page its get its own Vue app instance? That is, every pre-rendered page that is requested from the server behave as an SPA on the client.
  2. If #1 is true, does every page, and in effect, every app run isolated from all other pages and apps? No shared state?
  3. When using Vuex in SSG mode, does each page get its own Vuex store that is inflated with an initial state while rendering the page on the server? And, does this state get passed down to the client?
  4. This store is destroyed on navigating to a different page (or even refreshing the current page), to be replaced by a new one right?

CodePudding user response:

  1. In SSG, every page is rendered ahead of time but at the end, will be hydrated and hence become an SPA. Nuxt is basically Vue on steroids but it's still Vue.
  2. Not sure what you call isolated here, you can totally pass props, use emit etc... Meanwhile yeah, if you do have pages, they are not all loaded at the same time, there is code splitting lazy loading prefetching. Some info can be found here.
  3. You can have namespaced modules out of the box when using Vuex with Nuxt. You do have nuxtServerInit to pre-populate the store yes. You could give a read to the Nuxt lifecycle btw. But you don't have a Vuex module by page out of the box, there is no real usage for this IMO. And yeah, you'll get your Vuex store on the client of course.
  4. If you navigate to a different path with a <a></a> tag, you will nuke your SPA yeah. If you're using <nuxt-link></nuxt-link>, you'll stay in the SPA since the Vue router will make the "navigation". But yeah, if you type a path directly into the url and press Enter or refresh the page with F5, your entire SPA will be nuked and everything will be replaced from the ground up.

I've spoken at the latest Nuxt-nation, the quality is not amazing (sorry for this) but you could maybe get some interesting things out of it.

  • Related