From 932fbfddfdd54de23bec455abcb8118943084c7e Mon Sep 17 00:00:00 2001 From: Atinux Date: Tue, 7 Nov 2017 16:25:56 +0100 Subject: [PATCH] minor: Call routeChanged event with a 3rd argument if an error happened --- lib/app/client.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index 1c8f02d241..d3ab2760b3 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -132,6 +132,7 @@ async function loadAsyncComponents (to, from, next) { err = err || {} const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500 this.error({ statusCode, message: err.message }) + this.$nuxt.$emit('routeChanged', to, from, err) next(false) } } @@ -346,6 +347,7 @@ async function render (to, from, next) { await this.loadLayout(layout) this.error(error) + this.$nuxt.$emit('routeChanged', to, from, error) next(false) } } @@ -402,19 +404,20 @@ function fixPrepatch(to, ___) { }) } -function nuxtReady (app) { +function nuxtReady (_app) { window._nuxtReadyCbs.forEach((cb) => { if (typeof cb === 'function') { - cb(app) + cb(_app) } }) // Special JSDOM if (typeof window._onNuxtLoaded === 'function') { - window._onNuxtLoaded(app) + window._onNuxtLoaded(_app) } // Add router hooks router.afterEach(function (to, from) { - app.$nuxt.$emit('routeChanged', to, from) + // Wait for fixPrepatch + $data updates + Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from)) }) } @@ -531,7 +534,7 @@ async function mountApp(__app) { _app.setLayout(layout) // Mounts Vue app to DOM element - const mountApp = () => { + const mount = () => { _app.$mount('#__nuxt') // Listen for first Vue update @@ -564,7 +567,7 @@ async function mountApp(__app) { // If page already is server rendered if (NUXT.serverRendered) { - mountApp() + mount() return } @@ -575,11 +578,11 @@ async function mountApp(__app) { normalizeComponents(router.currentRoute, router.currentRoute) showNextPage.call(_app, router.currentRoute) // Dont call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render - mountApp() + mount() return } // Push the path and then mount app - router.push(path, () => mountApp(), (err) => console.error(err)) + router.push(path, () => mount(), (err) => console.error(err)) }) }