提交 177524be 编写于 作者: U undirectlookable 提交者: JJ Kasper

Fix conflict between defaultPathMap and default 404.html export (#8366)

* Fix conflict between defaultPathMap and default 404.html export,if have a page in pages/404.js

* Update packages/next/export/index.js
Co-Authored-By: NJJ Kasper <jj@jjsweb.site>

* add test export-override-404
上级 1e1eae2f
......@@ -140,7 +140,9 @@ export default async function (dir, options, configuration) {
distDir,
buildId
})
exportPathMap['/404.html'] = exportPathMap['/404.html'] || { page: '/_error' }
if (!exportPathMap['/404']) {
exportPathMap['/404.html'] = exportPathMap['/404.html'] || { page: '/_error' }
}
const exportPaths = Object.keys(exportPathMap)
const filteredPaths = exportPaths.filter(
// Remove API routes
......
export default () => <p>this is a 404 page override the default 404.html</p>
/* eslint-env jest */
/* global jasmine */
import fs from 'fs'
import { join } from 'path'
import { promisify } from 'util'
import { nextBuild, nextExport } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
const readFile = promisify(fs.readFile)
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
describe('Export with a page named 404.js', () => {
beforeAll(async () => {
await nextBuild(appDir)
await nextExport(appDir, { outdir })
})
it('should export a custom 404.html instead of default 404.html', async () => {
const html = await readFile(join(outdir, '404.html'), 'utf8')
expect(html).toMatch(/this is a 404 page override the default 404\.html/)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册