mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Fix error component on dynamic route.
This commit is contained in:
parent
a99161f685
commit
423f52f35d
@ -50,6 +50,8 @@ function loadAsyncComponents (to, ___, next) {
|
||||
|
||||
function render (to, from, next) {
|
||||
let Components = getMatchedComponents(to)
|
||||
this._dateLastError = this.$options._nuxt.dateErr
|
||||
this._hadError = !!this.$options._nuxt.err
|
||||
if (!Components.length) {
|
||||
// Default layout
|
||||
this.setLayout()
|
||||
@ -78,7 +80,6 @@ function render (to, from, next) {
|
||||
}
|
||||
})
|
||||
this.setTransitions(mapTransitions(Components, to, from))
|
||||
this.error()
|
||||
let nextCalled = false
|
||||
// Set layout
|
||||
this.setLayout(Components[0].options.layout)
|
||||
@ -100,7 +101,7 @@ function render (to, from, next) {
|
||||
return Promise.all(Components.map((Component, i) => {
|
||||
// Check if only children route changed
|
||||
Component._path = compile(to.matched[i].path)(to.params)
|
||||
if (Component._path === _lastPaths[i] && (i + 1) !== Components.length) {
|
||||
if (!this._hadError && Component._path === _lastPaths[i] && (i + 1) !== Components.length) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
let promises = []
|
||||
@ -177,6 +178,11 @@ function fixPrepatch (to, ___) {
|
||||
}
|
||||
return instance.constructor.options.__file
|
||||
})
|
||||
// hide error component if no error
|
||||
if (this._hadError && this._dateLastError === this.$options._nuxt.dateErr) {
|
||||
this.error()
|
||||
}
|
||||
// hot reloading
|
||||
hotReloadAPI(this)
|
||||
})
|
||||
}
|
||||
@ -353,6 +359,8 @@ Promise.all(resolveComponents)
|
||||
router.push(path)
|
||||
return
|
||||
}
|
||||
normalizeComponents(router.currentRoute, router.currentRoute)
|
||||
fixPrepatch.call(_app, router.currentRoute, router.currentRoute)
|
||||
mountApp()
|
||||
})
|
||||
})
|
||||
|
@ -71,11 +71,13 @@ const app = {
|
||||
return transitions
|
||||
},
|
||||
err: null,
|
||||
dateErr: null,
|
||||
error (err) {
|
||||
err = err || null
|
||||
if (typeof err === 'string') {
|
||||
err = { statusCode: 500, message: err }
|
||||
}
|
||||
this.$options._nuxt.dateErr = Date.now()
|
||||
this.$options._nuxt.err = err;
|
||||
return err
|
||||
}
|
||||
|
@ -157,6 +157,7 @@ function * generateRoutesAndFiles () {
|
||||
'router.js',
|
||||
'server.js',
|
||||
'utils.js',
|
||||
'components/nuxt-error.vue',
|
||||
'components/nuxt-loading.vue',
|
||||
'components/nuxt-child.js',
|
||||
'components/nuxt-link.js',
|
||||
@ -180,8 +181,7 @@ function * generateRoutesAndFiles () {
|
||||
loading: (typeof this.options.loading === 'string' ? r(this.srcDir, this.options.loading) : this.options.loading),
|
||||
transition: this.options.transition,
|
||||
components: {
|
||||
Loading: r(__dirname, 'app', 'components', 'nuxt-loading.vue'),
|
||||
ErrorPage: r(__dirname, 'app', 'components', 'nuxt-error.vue')
|
||||
ErrorPage: './nuxt-error.vue'
|
||||
}
|
||||
}
|
||||
// Format routes for the lib/app/router.js template
|
||||
|
Loading…
Reference in New Issue
Block a user