From 191f66a19b7643e927419ff50efff07cfae8cfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 2 Jul 2020 18:22:12 +0200 Subject: [PATCH] fix(vue-app): handle layout on client error (#7654) [release] --- packages/vue-app/template/client.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index 0418dfa9c7..1d3ba1fd3f 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -60,7 +60,7 @@ const logs = NUXT.logs || [] // Setup global Vue error handler if (!Vue.config.$nuxt) { const defaultErrorHandler = Vue.config.errorHandler - Vue.config.errorHandler = (err, vm, info, ...rest) => { + Vue.config.errorHandler = async (err, vm, info, ...rest) => { // Call other handler if exist let handled = null if (typeof defaultErrorHandler === 'function') { @@ -76,7 +76,19 @@ if (!Vue.config.$nuxt) { // Show Nuxt Error Page if (nuxtApp && vm.$root[nuxtApp].error && info !== 'render function') { - vm.$root[nuxtApp].error(err) + const currentApp = vm.$root[nuxtApp] + <% if (features.layouts) { %> + // Load error layout + let layout = (NuxtError.options || NuxtError).layout + if (typeof layout === 'function') { + layout = layout(currentApp.context) + } + if (layout) { + await currentApp.loadLayout(layout).catch(() => {}) + } + currentApp.setLayout(layout) + <% } %> + currentApp.error(err) } }