mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
fix: Dont call pages asyncData/fetch if middleware redirected or errored
This commit is contained in:
parent
8157fbfde9
commit
a2cc3afe60
@ -97,8 +97,8 @@ function mapTransitions(Components, to, from) {
|
||||
}
|
||||
|
||||
async function loadAsyncComponents (to, from, next) {
|
||||
// Check if route path changed (this._pathChanged)
|
||||
this._pathChanged = from.path !== to.path
|
||||
// Check if route path changed (this._pathChanged), only if the page is not an error (for validate())
|
||||
this._pathChanged = !!app.nuxt.err || from.path !== to.path
|
||||
|
||||
<% if (loading) { %>
|
||||
if (this._pathChanged && this.$loading.start) {
|
||||
@ -223,6 +223,7 @@ async function render (to, from, next) {
|
||||
// Call middleware
|
||||
await callMiddleware.call(this, Components, app.context)
|
||||
if (app.context._redirected) return
|
||||
if (app.context._errored) return next()
|
||||
|
||||
// Set layout
|
||||
let layout = Components[0].options.layout
|
||||
@ -234,6 +235,7 @@ async function render (to, from, next) {
|
||||
// Call middleware for layout
|
||||
await callMiddleware.call(this, Components, app.context, layout)
|
||||
if (app.context._redirected) return
|
||||
if (app.context._errored) return next()
|
||||
|
||||
// Call .validate()
|
||||
let isValid = true
|
||||
|
@ -80,6 +80,7 @@ async function createApp (ssrContext) {
|
||||
dateErr: null,
|
||||
error (err) {
|
||||
err = err || null
|
||||
app.context._errored = !!err
|
||||
if (typeof err === 'string') err = { statusCode: 500, message: err }
|
||||
const nuxt = this.nuxt || this.$options.nuxt
|
||||
nuxt.dateErr = Date.now()
|
||||
|
@ -186,6 +186,7 @@ export async function setContext(app, context) {
|
||||
// Dynamic keys
|
||||
app.context.next = context.next
|
||||
app.context._redirected = false
|
||||
app.context._errored = false
|
||||
app.context.isHMR = !!context.isHMR
|
||||
if (context.route) app.context.route = await getRouteData(context.route)
|
||||
app.context.params = app.context.route.params || {}
|
||||
@ -194,7 +195,7 @@ export async function setContext(app, context) {
|
||||
}
|
||||
|
||||
export function middlewareSeries(promises, appContext) {
|
||||
if (!promises.length || appContext._redirected || appContext.app.nuxt.err) {
|
||||
if (!promises.length || appContext._redirected || appContext._errored) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return promisify(promises[0], appContext)
|
||||
|
Loading…
Reference in New Issue
Block a user