diff --git a/lib/app/client.js b/lib/app/client.js
index 41101736a9..db3edeeb11 100644
--- a/lib/app/client.js
+++ b/lib/app/client.js
@@ -386,18 +386,10 @@ Promise.all(resolveComponents)
.then((Components) => {
const _app = new Vue(app)
- let context = getContext({ to: router.currentRoute, isClient: true<%= (store ? ', store' : '') %> })
- let layoutName = 'default'
- return callMiddleware.call(_app, Components, context)
+ let layout = NUXT.layout || 'default'
+ return _app.loadLayout(layout)
.then(() => {
- layoutName = Components.length ? Components[0].options.layout : NuxtError.layout
- if (typeof layoutName === 'function') {
- layoutName = layoutName(context)
- }
- return _app.loadLayout(layoutName)
- })
- .then(() => {
- _app.setLayout(layoutName)
+ _app.setLayout(layout)
return { _app, Components }
})
})
diff --git a/lib/app/server.js b/lib/app/server.js
index 600320f523..fa5cff0c75 100644
--- a/lib/app/server.js
+++ b/lib/app/server.js
@@ -22,7 +22,7 @@ export default context => {
// Add store to the context
<%= (store ? 'context.store = store' : '') %>
// Nuxt object
- context.nuxt = { data: [], error: null<%= (store ? ', state: null' : '') %>, serverRendered: true }
+ context.nuxt = { layout: 'default', data: [], error: null<%= (store ? ', state: null' : '') %>, serverRendered: true }
// create context.next for simulate next() of beforeEach() when wanted to redirect
context.redirected = false
context.next = function (opts) {
@@ -120,6 +120,8 @@ export default context => {
return _app.loadLayout(layout).then(() => _app.setLayout(layout))
})
.then((layout) => {
+ // Set layout to __NUXT__
+ context.nuxt.layout = _app.layoutName
// Call middleware (layout + pages)
let midd = []
if (layout.middleware) {
@@ -202,7 +204,16 @@ export default context => {
context.nuxt.error = _app.$options._nuxt.err
<%= (store ? '// Add the state from the vuex store' : '') %>
<%= (store ? 'context.nuxt.state = store.state' : '') %>
- return _app
+ // If no error, return main app
+ if (!context.nuxt.error) {
+ return _app
+ }
+ // Load layout for error page
+ let layout = (typeof NuxtError.layout === 'function' ? NuxtError.layout(ctx) : NuxtError.layout)
+ context.nuxt.layout = layout || ''
+ return _app.loadLayout(layout)
+ .then(() => _app.setLayout(layout))
+ .then(() => _app)
})
.catch(function (error) {
if (!componentsLoaded && error instanceof Error) {
diff --git a/lib/build.js b/lib/build.js
index ca772683b3..43e664aeb4 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -371,8 +371,8 @@ function getWebpackServerConfig () {
function createWebpackMiddleware () {
const clientConfig = getWebpackClientConfig.call(this)
- const host = process.env.HOST || process.env.npm_package_config_nuxt_port || '127.0.0.1'
- const port = process.env.PORT || process.env.npm_package_config_nuxt_host || '3000'
+ const host = process.env.HOST || process.env.npm_package_config_nuxt_host || '127.0.0.1'
+ const port = process.env.PORT || process.env.npm_package_config_nuxt_port || '3000'
// setup on the fly compilation + hot-reload
clientConfig.entry.app = _.flatten(['webpack-hot-middleware/client?reload=true', clientConfig.entry.app])
clientConfig.plugins.push(
diff --git a/test/fixtures/with-config/layouts/error.vue b/test/fixtures/with-config/layouts/error.vue
index 7694d81b29..f50245f857 100644
--- a/test/fixtures/with-config/layouts/error.vue
+++ b/test/fixtures/with-config/layouts/error.vue
@@ -1,3 +1,9 @@
Never displayedError page
+
+
diff --git a/test/fixtures/with-config/pages/error.vue b/test/fixtures/with-config/pages/error.vue
new file mode 100644
index 0000000000..f309c03407
--- /dev/null
+++ b/test/fixtures/with-config/pages/error.vue
@@ -0,0 +1,11 @@
+
+