diff --git a/lib/app/client.js b/lib/app/client.js index 8f8eee1d3c..d5fdba931b 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -336,12 +336,6 @@ const NUXT = window.__NUXT__ || {} if (!NUXT) { throw new Error('[nuxt.js] cannot find the global variable __NUXT__, make sure the server is working.') } -<% if (store) { %> -// Replace store state -if (NUXT.state) { - store.replaceState(NUXT.state) -} -<% } %> // Get matched components const path = getLocation(router.options.base) const resolveComponents = flatMapComponents(router.match(path), (Component, _, match, key, index) => { diff --git a/lib/app/index.js b/lib/app/index.js index dd14678474..45040673e1 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -26,6 +26,12 @@ Vue.use(Meta, { }) if (process.browser) { + <% if (store) { %> + // Replace store state before calling plugins + if (window.__NUXT__ && window.__NUXT__.state) { + store.replaceState(window.__NUXT__.state) + } + <% } %> // window.onNuxtReady(() => console.log('Ready')) hook // Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) window._nuxtReadyCbs = []