diff --git a/lib/builder/builder.js b/lib/builder/builder.js
index a9ec11e2dd..fb543a95e6 100644
--- a/lib/builder/builder.js
+++ b/lib/builder/builder.js
@@ -227,10 +227,10 @@ export default class Builder extends Tapable {
// -- Layouts --
if (fs.existsSync(resolve(this.options.srcDir, 'layouts'))) {
- const layoutsFiles = await glob('layouts/*.vue', { cwd: this.options.srcDir })
+ const layoutsFiles = await glob('layouts/**/*.vue', { cwd: this.options.srcDir })
let hasErrorLayout = false
layoutsFiles.forEach((file) => {
- let name = file.split('/').slice(-1)[0].replace(/\.vue$/, '')
+ let name = file.split('/').slice(1).join('/').replace(/\.vue$/, '')
if (name === 'error') {
hasErrorLayout = true
return
diff --git a/test/fixtures/with-config/layouts/desktop/default.vue b/test/fixtures/with-config/layouts/desktop/default.vue
new file mode 100644
index 0000000000..329274e836
--- /dev/null
+++ b/test/fixtures/with-config/layouts/desktop/default.vue
@@ -0,0 +1,20 @@
+
+
+
Default desktop layout
+
+
+
+
+
diff --git a/test/fixtures/with-config/layouts/mobile/default.vue b/test/fixtures/with-config/layouts/mobile/default.vue
new file mode 100644
index 0000000000..548fe9b27b
--- /dev/null
+++ b/test/fixtures/with-config/layouts/mobile/default.vue
@@ -0,0 +1,21 @@
+
+
+
Default mobile layout
+
+
+
+
+
+
diff --git a/test/fixtures/with-config/pages/desktop.vue b/test/fixtures/with-config/pages/desktop.vue
new file mode 100644
index 0000000000..4c0951062e
--- /dev/null
+++ b/test/fixtures/with-config/pages/desktop.vue
@@ -0,0 +1,12 @@
+
+
+
Desktop page
+
+
+
+
+
diff --git a/test/fixtures/with-config/pages/mobile.vue b/test/fixtures/with-config/pages/mobile.vue
new file mode 100644
index 0000000000..915e603c6e
--- /dev/null
+++ b/test/fixtures/with-config/pages/mobile.vue
@@ -0,0 +1,12 @@
+
+
+
Mobile page
+
+
+
+
+
diff --git a/test/with-config.test.js b/test/with-config.test.js
index 579affa5cd..c0bfe0674b 100644
--- a/test/with-config.test.js
+++ b/test/with-config.test.js
@@ -61,6 +61,22 @@ test('/test/about (custom layout)', async t => {
t.true(html.includes('About page
'))
})
+test('/test/desktop (custom layout in desktop folder)', async t => {
+ const window = await nuxt.renderAndGetWindow(url('/test/desktop'))
+ const html = window.document.body.innerHTML
+ t.is(window.__NUXT__.layout, 'desktop/default')
+ t.true(html.includes('Default desktop layout
'))
+ t.true(html.includes('Desktop page
'))
+})
+
+test('/test/mobile (custom layout in mobile folder)', async t => {
+ const window = await nuxt.renderAndGetWindow(url('/test/mobile'))
+ const html = window.document.body.innerHTML
+ t.is(window.__NUXT__.layout, 'mobile/default')
+ t.true(html.includes('Default mobile layout
'))
+ t.true(html.includes('Mobile page
'))
+})
+
test('/test/env', async t => {
const window = await nuxt.renderAndGetWindow(url('/test/env'))
const html = window.document.body.innerHTML
@@ -95,7 +111,7 @@ test('/test/about-bis (added with extendRoutes)', async t => {
test('Check stats.json generated by build.analyze', t => {
const stats = require(resolve(__dirname, 'fixtures/with-config/.nuxt/dist/stats.json'))
- t.is(stats.assets.length, 27)
+ t.is(stats.assets.length, 35)
})
test('Check /test/test.txt with custom serve-static options', async t => {