Preview mode
Live Preview for target static with the preview mode
With Nuxt and full static you can now use live preview out of the box which will call your API or your CMS so you can see the changes live before deploying.
target:static The preview mode will automatically refresh the page data as it uses $nuxt.refresh under the hood and therefore calls nuxtServerInit, asyncData and fetch on the client side.
In order to activate live preview you will need to add the following plugin:
export default function ({ query, enablePreview }) {
  if (query.preview) {
    enablePreview()
  }
}
 enablePreview is only available in the context object of plugins. Previews are handled client-side and
thus the plugin should be run on the client: preview.client.jsexport default {
  plugins: ['~/plugins/preview.client.js']
}
 Once you have added the plugin you can now generate your site and serve it.
yarn generate
yarn start
 npx nuxt generate
npx nuxt start
 Then you can see your preview page by adding the query param to the end of the page you want to see once:
?preview=true
 Previewing pages that are not yet generated
For pages that are not yet generated, SPA fallback will still call the API before showing the 404 page as these pages exist on the API but are not generated yet.
If you have set a validate hook, you will probably need to modify it so that it doesn't redirect to the 404 page in preview mode.
validate({ params, query }) {
  if (query.preview) {
    return true
  }
}
 Passing data to enablePreview
You can pass data to the enablePreview function. That data will then be available on the $preview context helper and on this.$preview.
What's next
 
        Sébastien Chopin
       
 
        Nazaré da Piedade
       
 
        Nobu
       
 
        川音리오
       
 
        Maciek Palmowski
       
 
        Nestor Vera
       
 
        Daniel Roe
       
 
        Yue Yang
       
 
        Jeronimas
       
 
        Alessandro Carrano
       
 
        Clément Ollivier
       
 
        Alexander Lichter
       
 
        N3-rd
       
 
        Adrien Zaganelli
       
 
        Mag
       
 
        Stefan Huber
       
 
        Olga Bulat
       
 
        Paiva
       
 
        Florian Reuschel
       
 
        Savas Vedova
       
 
        Steven
       
 
        Vinícius Alves
       
 
        Kareem Dabbeet
       
 
        Valentín Costa
       
 
        Ryan Skinner
       
 
        Alex Hirzel
       
 
        Ajeet Chaulagain
       
 
        René Eschke
       
 
        Nico Devs
       
 
        Muhammad
       
 
        Naoki Hamada
       
 
        Tom
       
 
        Yann Aufray
       
 
        Anthony Chu
       
 
        Nuzhat Minhaz
       
 
        Lucas Portet
       
 
        Richard Schloss
       
 
        Bobby
       
 
        bpy
       
 
        Antony Konstantinidis
       
 
        Hibariya
       
 
        Jose Seabra
       
 
        Eze
       
 
        Florian Lefebvre
       
 
        Lucas Recoaro
       
 
        Julien SEIXAS