diff --git a/lib/app/client.js b/lib/app/client.js index 8278159aae..5e5522cb2d 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -222,20 +222,14 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m return Component }) -// window.onNuxtReady(() => console.log('Ready')) hook -// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) -let _readyCbs = [] -window.onNuxtReady = function (cb) { - _readyCbs.push(cb) -} function nuxtReady (app) { - _readyCbs.forEach((cb) => { + window._nuxtReadyCbs.forEach((cb) => { if (typeof cb === 'function') { cb(app) } }) // Add router hooks - router.afterEach(function (to) { + router.afterEach(function (to, from) { app.$nuxt.$emit('routeChanged', to, from) }) } diff --git a/lib/app/index.js b/lib/app/index.js index dfd79a443b..86daac5d69 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -21,6 +21,15 @@ Vue.use(Meta, { tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag }) +if (process.BROWSER_BUILD) { + // window.onNuxtReady(() => console.log('Ready')) hook + // Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) + window._nuxtReadyCbs = [] + window.onNuxtReady = function (cb) { + window._nuxtReadyCbs.push(cb) + } +} + // Includes external plugins <% plugins.forEach(function (pluginPath) { %> require('<%= pluginPath %>')