fix: Handle redirect in middleware, fix #542 and #2665

This commit is contained in:
Sébastien Chopin 2018-01-26 12:16:53 +01:00
parent 5f50d402d5
commit 1ab4be456f

View File

@ -226,11 +226,11 @@ async function render (to, from, next) {
if (!Components.length) { if (!Components.length) {
// Default layout // Default layout
await callMiddleware.call(this, Components, app.context) await callMiddleware.call(this, Components, app.context)
if (app.context._redirected) return if (nextCalled) return
// Load layout for error page // Load layout for error page
const layout = await this.loadLayout(typeof NuxtError.layout === 'function' ? NuxtError.layout(app.context) : NuxtError.layout) const layout = await this.loadLayout(typeof NuxtError.layout === 'function' ? NuxtError.layout(app.context) : NuxtError.layout)
await callMiddleware.call(this, Components, app.context, layout) await callMiddleware.call(this, Components, app.context, layout)
if (app.context._redirected) return if (nextCalled) return
// Show error page // Show error page
app.context.error({ statusCode: 404, message: '<%= messages.error_404 %>' }) app.context.error({ statusCode: 404, message: '<%= messages.error_404 %>' })
return next() return next()
@ -250,7 +250,7 @@ async function render (to, from, next) {
try { try {
// Call middleware // Call middleware
await callMiddleware.call(this, Components, app.context) await callMiddleware.call(this, Components, app.context)
if (app.context._redirected) return if (nextCalled) return
if (app.context._errored) return next() if (app.context._errored) return next()
// Set layout // Set layout
@ -262,7 +262,7 @@ async function render (to, from, next) {
// Call middleware for layout // Call middleware for layout
await callMiddleware.call(this, Components, app.context, layout) await callMiddleware.call(this, Components, app.context, layout)
if (app.context._redirected) return if (nextCalled) return
if (app.context._errored) return next() if (app.context._errored) return next()
// Call .validate() // Call .validate()