diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index db1c2457a2..f88b14169c 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -145,8 +145,19 @@ async function loadAsyncComponents(to, from, next) { // Call next() next() } catch (err) { - const error = this.error(err) - this.<%= globals.nuxt %>.$emit('routeChanged', to, from, error) + err = err || {} + const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500 + const message = err.message || '' + + // Handle chunk loading errors + // This may be due to a new deployment or a network problem + if (/^Loading chunk (\d)+ failed\./.test(message)) { + window.location.reload(true /* skip cache */) + return // prevent error page blinking for user + } + + this.error({ statusCode, message }) + this.$nuxt.$emit('routeChanged', to, from, err) next(false) } }