Replace store state the soonest possible

This commit is contained in:
Sébastien Chopin 2017-03-24 01:35:57 +01:00
parent 474f68e46e
commit 4034801fc9
2 changed files with 6 additions and 6 deletions

View File

@ -336,12 +336,6 @@ const NUXT = window.__NUXT__ || {}
if (!NUXT) { if (!NUXT) {
throw new Error('[nuxt.js] cannot find the global variable __NUXT__, make sure the server is working.') 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 // Get matched components
const path = getLocation(router.options.base) const path = getLocation(router.options.base)
const resolveComponents = flatMapComponents(router.match(path), (Component, _, match, key, index) => { const resolveComponents = flatMapComponents(router.match(path), (Component, _, match, key, index) => {

View File

@ -26,6 +26,12 @@ Vue.use(Meta, {
}) })
if (process.browser) { 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 // window.onNuxtReady(() => console.log('Ready')) hook
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) // Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
window._nuxtReadyCbs = [] window._nuxtReadyCbs = []