mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
parent
b6457545be
commit
af76e07b56
@ -349,7 +349,8 @@ export default class Builder {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!templateVars.layouts[name] && /\.vue$/.test(file)) {
|
// .vue file takes precedence over other extensions
|
||||||
|
if (!templateVars.layouts[name] || /\.vue$/.test(file)) {
|
||||||
templateVars.layouts[name] = this.relativeToBuild(
|
templateVars.layouts[name] = this.relativeToBuild(
|
||||||
this.options.srcDir,
|
this.options.srcDir,
|
||||||
file
|
file
|
||||||
@ -382,6 +383,7 @@ export default class Builder {
|
|||||||
ignore: this.options.ignore
|
ignore: this.options.ignore
|
||||||
})).forEach((f) => {
|
})).forEach((f) => {
|
||||||
const key = f.replace(new RegExp(`\\.(${this.supportedExtensions.join('|')})$`), '')
|
const key = f.replace(new RegExp(`\\.(${this.supportedExtensions.join('|')})$`), '')
|
||||||
|
// .vue file takes precedence over other extensions
|
||||||
if (/\.vue$/.test(f) || !files[key]) {
|
if (/\.vue$/.test(f) || !files[key]) {
|
||||||
files[key] = f.replace(/(['"])/g, '\\$1')
|
files[key] = f.replace(/(['"])/g, '\\$1')
|
||||||
}
|
}
|
||||||
|
10
test/fixtures/basic/layouts/custom.js
vendored
Normal file
10
test/fixtures/basic/layouts/custom.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export default {
|
||||||
|
render(h) {
|
||||||
|
return h('div',
|
||||||
|
[
|
||||||
|
h('h1', 'JS Layout'),
|
||||||
|
h('nuxt')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
5
test/fixtures/basic/layouts/default.vue
vendored
Normal file
5
test/fixtures/basic/layouts/default.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<Nuxt />
|
||||||
|
</div>
|
||||||
|
</template>
|
6
test/fixtures/basic/pages/custom.js
vendored
Normal file
6
test/fixtures/basic/pages/custom.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
layout: 'custom',
|
||||||
|
render(h) {
|
||||||
|
return h('h2', 'custom page')
|
||||||
|
}
|
||||||
|
}
|
4
test/fixtures/spa/layouts/custom.vue
vendored
4
test/fixtures/spa/layouts/custom.vue
vendored
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
Custom layout
|
Custom layout
|
||||||
<br>
|
<br>
|
||||||
<Nuxt />
|
<Nuxt />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
4
test/fixtures/spa/layouts/default.vue
vendored
4
test/fixtures/spa/layouts/default.vue
vendored
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
Default layout
|
Default layout
|
||||||
<br>
|
<br>
|
||||||
<Nuxt />
|
<Nuxt />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -331,6 +331,13 @@ describe('basic ssr', () => {
|
|||||||
expect(html).toMatch('Hello unicode')
|
expect(html).toMatch('Hello unicode')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/custom (js layout)', async () => {
|
||||||
|
const window = await nuxt.server.renderAndGetWindow(url('/custom'))
|
||||||
|
const html = window.document.body.innerHTML
|
||||||
|
expect(html).toMatch('<h1>JS Layout</h1>')
|
||||||
|
expect(html).toMatch('<h2>custom page</h2>')
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user