minor: Call routeChanged event with a 3rd argument if an error happened

This commit is contained in:
Atinux 2017-11-07 16:25:56 +01:00
parent 711e6a916e
commit 932fbfddfd

View File

@ -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))
})
}