mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-03 19:07:15 +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) {
|
function render (to, from, next) {
|
||||||
let Components = getMatchedComponents(to)
|
let Components = getMatchedComponents(to)
|
||||||
|
this._dateLastError = this.$options._nuxt.dateErr
|
||||||
|
this._hadError = !!this.$options._nuxt.err
|
||||||
if (!Components.length) {
|
if (!Components.length) {
|
||||||
// Default layout
|
// Default layout
|
||||||
this.setLayout()
|
this.setLayout()
|
||||||
@ -78,7 +80,6 @@ function render (to, from, next) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.setTransitions(mapTransitions(Components, to, from))
|
this.setTransitions(mapTransitions(Components, to, from))
|
||||||
this.error()
|
|
||||||
let nextCalled = false
|
let nextCalled = false
|
||||||
// Set layout
|
// Set layout
|
||||||
this.setLayout(Components[0].options.layout)
|
this.setLayout(Components[0].options.layout)
|
||||||
@ -100,7 +101,7 @@ function render (to, from, next) {
|
|||||||
return Promise.all(Components.map((Component, i) => {
|
return Promise.all(Components.map((Component, i) => {
|
||||||
// Check if only children route changed
|
// Check if only children route changed
|
||||||
Component._path = compile(to.matched[i].path)(to.params)
|
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()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
let promises = []
|
let promises = []
|
||||||
@ -177,6 +178,11 @@ function fixPrepatch (to, ___) {
|
|||||||
}
|
}
|
||||||
return instance.constructor.options.__file
|
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)
|
hotReloadAPI(this)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -353,6 +359,8 @@ Promise.all(resolveComponents)
|
|||||||
router.push(path)
|
router.push(path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
normalizeComponents(router.currentRoute, router.currentRoute)
|
||||||
|
fixPrepatch.call(_app, router.currentRoute, router.currentRoute)
|
||||||
mountApp()
|
mountApp()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -71,11 +71,13 @@ const app = {
|
|||||||
return transitions
|
return transitions
|
||||||
},
|
},
|
||||||
err: null,
|
err: null,
|
||||||
|
dateErr: null,
|
||||||
error (err) {
|
error (err) {
|
||||||
err = err || null
|
err = err || null
|
||||||
if (typeof err === 'string') {
|
if (typeof err === 'string') {
|
||||||
err = { statusCode: 500, message: err }
|
err = { statusCode: 500, message: err }
|
||||||
}
|
}
|
||||||
|
this.$options._nuxt.dateErr = Date.now()
|
||||||
this.$options._nuxt.err = err;
|
this.$options._nuxt.err = err;
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,7 @@ function * generateRoutesAndFiles () {
|
|||||||
'router.js',
|
'router.js',
|
||||||
'server.js',
|
'server.js',
|
||||||
'utils.js',
|
'utils.js',
|
||||||
|
'components/nuxt-error.vue',
|
||||||
'components/nuxt-loading.vue',
|
'components/nuxt-loading.vue',
|
||||||
'components/nuxt-child.js',
|
'components/nuxt-child.js',
|
||||||
'components/nuxt-link.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),
|
loading: (typeof this.options.loading === 'string' ? r(this.srcDir, this.options.loading) : this.options.loading),
|
||||||
transition: this.options.transition,
|
transition: this.options.transition,
|
||||||
components: {
|
components: {
|
||||||
Loading: r(__dirname, 'app', 'components', 'nuxt-loading.vue'),
|
ErrorPage: './nuxt-error.vue'
|
||||||
ErrorPage: r(__dirname, 'app', 'components', 'nuxt-error.vue')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Format routes for the lib/app/router.js template
|
// Format routes for the lib/app/router.js template
|
||||||
|
Loading…
Reference in New Issue
Block a user