mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
This commit is contained in:
parent
72479687d9
commit
6e8a51509c
@ -223,7 +223,6 @@ export default class Builder {
|
|||||||
cwd: this.options.srcDir,
|
cwd: this.options.srcDir,
|
||||||
ignore: this.options.ignore
|
ignore: this.options.ignore
|
||||||
})
|
})
|
||||||
let hasErrorLayout = false
|
|
||||||
layoutsFiles.forEach((file) => {
|
layoutsFiles.forEach((file) => {
|
||||||
const name = file
|
const name = file
|
||||||
.split('/')
|
.split('/')
|
||||||
@ -231,7 +230,12 @@ export default class Builder {
|
|||||||
.join('/')
|
.join('/')
|
||||||
.replace(/\.(vue|js)$/, '')
|
.replace(/\.(vue|js)$/, '')
|
||||||
if (name === 'error') {
|
if (name === 'error') {
|
||||||
hasErrorLayout = true
|
if (!templateVars.components.ErrorPage) {
|
||||||
|
templateVars.components.ErrorPage = this.relativeToBuild(
|
||||||
|
this.options.srcDir,
|
||||||
|
file
|
||||||
|
)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!templateVars.layouts[name] || /\.vue$/.test(file)) {
|
if (!templateVars.layouts[name] || /\.vue$/.test(file)) {
|
||||||
@ -241,12 +245,6 @@ export default class Builder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!templateVars.components.ErrorPage && hasErrorLayout) {
|
|
||||||
templateVars.components.ErrorPage = this.relativeToBuild(
|
|
||||||
this.options.srcDir,
|
|
||||||
`${this.options.dir.layouts}/error.vue`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// If no default layout, create its folder and add the default folder
|
// If no default layout, create its folder and add the default folder
|
||||||
if (!templateVars.layouts.default) {
|
if (!templateVars.layouts.default) {
|
||||||
|
@ -71,6 +71,16 @@ export default class ModuleContainer {
|
|||||||
|
|
||||||
// Add to nuxt layouts
|
// Add to nuxt layouts
|
||||||
this.options.layouts[name || path.parse(src).name] = `./${dst}`
|
this.options.layouts[name || path.parse(src).name] = `./${dst}`
|
||||||
|
|
||||||
|
// If error layout, set ErrorPage
|
||||||
|
if (name === 'error') {
|
||||||
|
this.addErrorLayout(dst)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addErrorLayout(dst) {
|
||||||
|
const relativeBuildDir = path.relative(this.options.rootDir, this.options.buildDir)
|
||||||
|
this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`
|
||||||
}
|
}
|
||||||
|
|
||||||
addServerMiddleware(middleware) {
|
addServerMiddleware(middleware) {
|
||||||
|
6
test/fixtures/module/modules/layout/index.js
vendored
Normal file
6
test/fixtures/module/modules/layout/index.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { resolve } from 'path'
|
||||||
|
|
||||||
|
export default function module() {
|
||||||
|
this.addLayout(
|
||||||
|
{ src: resolve(__dirname, 'some-error.vue') }, 'error')
|
||||||
|
}
|
3
test/fixtures/module/modules/layout/some-error.vue
vendored
Normal file
3
test/fixtures/module/modules/layout/some-error.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<h1>You should see the error in a different Vue!</h1>
|
||||||
|
</template>
|
1
test/fixtures/module/nuxt.config.js
vendored
1
test/fixtures/module/nuxt.config.js
vendored
@ -3,6 +3,7 @@ export default {
|
|||||||
modules: [
|
modules: [
|
||||||
'~~/modules/basic',
|
'~~/modules/basic',
|
||||||
'~/modules/hooks',
|
'~/modules/hooks',
|
||||||
|
'~/modules/layout',
|
||||||
{
|
{
|
||||||
src: '~/modules/middleware',
|
src: '~/modules/middleware',
|
||||||
options: {
|
options: {
|
||||||
|
@ -31,6 +31,11 @@ describe('module', () => {
|
|||||||
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/404 should display the module error layout', async () => {
|
||||||
|
const { html } = await nuxt.renderRoute('/404')
|
||||||
|
expect(html).toContain('You should see the error in a different Vue!')
|
||||||
|
})
|
||||||
|
|
||||||
test('Hooks', () => {
|
test('Hooks', () => {
|
||||||
expect(nuxt.__module_hook).toBe(1)
|
expect(nuxt.__module_hook).toBe(1)
|
||||||
expect(nuxt.__renderer_hook).toBe(2)
|
expect(nuxt.__renderer_hook).toBe(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user