Skip to content

Commit 578d5d4

Browse files
clarkdopi0
authored andcommitted
fix(vue-app): error page layout not correctly applied in client rendering (nuxt#6479)
1 parent 950b48f commit 578d5d4

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

packages/vue-app/template/App.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
globalHandleError
77
} from './utils'
88
<% } %>
9+
<% if (features.layouts && components.ErrorPage) { %>import NuxtError from '<%= components.ErrorPage %>'<% } %>
910
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %>
1011
<% if (buildIndicator) { %>import NuxtBuildIndicator from './components/nuxt-build-indicator'<% } %>
1112
<% css.forEach((c) => { %>
@@ -35,6 +36,15 @@ export default {
3536
render (h, props) {
3637
<% if (loading) { %>const loadingEl = h('NuxtLoading', { ref: 'loading' })<% } %>
3738
<% if (features.layouts) { %>
39+
<% if (components.ErrorPage) { %>
40+
if (this.nuxt.err && NuxtError.layout) {
41+
this.setLayout(
42+
typeof NuxtError.layout === 'function'
43+
? NuxtError.layout(this.context)
44+
: NuxtError.layout
45+
)
46+
}
47+
<% } %>
3848
const layoutEl = h(this.layout || 'nuxt')
3949
const templateEl = h('div', {
4050
domProps: {

test/e2e/error.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('basic browser', () => {
3232
test('/squared doesnt loop due to error on error page', async () => {
3333
await page.nuxt.navigate('/squared')
3434

35+
expect(await page.$text('header')).toBe('Error layout')
3536
expect(await page.$text('h2')).toBe('An error occured while showing the error page')
3637
})
3738

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div>
3+
<header>Error layout</header>
4+
<nuxt />
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
name: 'ErrorLayout'
11+
}
12+
</script>

test/fixtures/error/layouts/error.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<script>
1313
export default {
14+
layout: 'error-layout',
1415
// eslint-disable-next-line vue/require-prop-types
1516
props: ['error']
1617
}

0 commit comments

Comments
 (0)