mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 14:41:25 +00:00
minor: Call routeChanged event with a 3rd argument if an error happened
This commit is contained in:
parent
711e6a916e
commit
932fbfddfd
@ -132,6 +132,7 @@ async function loadAsyncComponents (to, from, next) {
|
|||||||
err = err || {}
|
err = err || {}
|
||||||
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
|
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
|
||||||
this.error({ statusCode, message: err.message })
|
this.error({ statusCode, message: err.message })
|
||||||
|
this.$nuxt.$emit('routeChanged', to, from, err)
|
||||||
next(false)
|
next(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,6 +347,7 @@ async function render (to, from, next) {
|
|||||||
await this.loadLayout(layout)
|
await this.loadLayout(layout)
|
||||||
|
|
||||||
this.error(error)
|
this.error(error)
|
||||||
|
this.$nuxt.$emit('routeChanged', to, from, error)
|
||||||
next(false)
|
next(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -402,19 +404,20 @@ function fixPrepatch(to, ___) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function nuxtReady (app) {
|
function nuxtReady (_app) {
|
||||||
window._nuxtReadyCbs.forEach((cb) => {
|
window._nuxtReadyCbs.forEach((cb) => {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
cb(app)
|
cb(_app)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Special JSDOM
|
// Special JSDOM
|
||||||
if (typeof window._onNuxtLoaded === 'function') {
|
if (typeof window._onNuxtLoaded === 'function') {
|
||||||
window._onNuxtLoaded(app)
|
window._onNuxtLoaded(_app)
|
||||||
}
|
}
|
||||||
// Add router hooks
|
// Add router hooks
|
||||||
router.afterEach(function (to, from) {
|
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)
|
_app.setLayout(layout)
|
||||||
|
|
||||||
// Mounts Vue app to DOM element
|
// Mounts Vue app to DOM element
|
||||||
const mountApp = () => {
|
const mount = () => {
|
||||||
_app.$mount('#__nuxt')
|
_app.$mount('#__nuxt')
|
||||||
|
|
||||||
// Listen for first Vue update
|
// Listen for first Vue update
|
||||||
@ -564,7 +567,7 @@ async function mountApp(__app) {
|
|||||||
|
|
||||||
// If page already is server rendered
|
// If page already is server rendered
|
||||||
if (NUXT.serverRendered) {
|
if (NUXT.serverRendered) {
|
||||||
mountApp()
|
mount()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,11 +578,11 @@ async function mountApp(__app) {
|
|||||||
normalizeComponents(router.currentRoute, router.currentRoute)
|
normalizeComponents(router.currentRoute, router.currentRoute)
|
||||||
showNextPage.call(_app, router.currentRoute)
|
showNextPage.call(_app, router.currentRoute)
|
||||||
// Dont call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render
|
// Dont call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render
|
||||||
mountApp()
|
mount()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push the path and then mount app
|
// Push the path and then mount app
|
||||||
router.push(path, () => mountApp(), (err) => console.error(err))
|
router.push(path, () => mount(), (err) => console.error(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user