Unverified Commit ce0a32c3 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Make sure to not duplicate exports with exportTrailingSlash (#11011)

This makes sure we don't duplicate the `/` route or any others while exporting with `exportTrailingSlash` enabled. We do still output `404.html` with `exportTrailingSlash` enabled in case anyone was relying on this file being present.

Fixes: https://github.com/zeit/next.js/issues/11008
parent 83bc82e4
...@@ -277,12 +277,22 @@ export default async function exportApp( ...@@ -277,12 +277,22 @@ export default async function exportApp(
distDir, distDir,
buildId, buildId,
}) })
if (!exportPathMap['/404'] && !exportPathMap['/404.html']) { if (!exportPathMap['/404'] && !exportPathMap['/404.html']) {
exportPathMap['/404'] = exportPathMap['/404.html'] = { exportPathMap['/404'] = exportPathMap['/404.html'] = {
page: '/_error', page: '/_error',
} }
} }
const exportPaths = Object.keys(exportPathMap)
// make sure to prevent duplicates
const exportPaths = [
...new Set(
Object.keys(exportPathMap).map(
(path) => normalizePagePath(path).replace(/^\/index$/, '') || '/'
)
),
]
const filteredPaths = exportPaths.filter( const filteredPaths = exportPaths.filter(
// Remove API routes // Remove API routes
(route) => !exportPathMap[route].page.match(API_ROUTE) (route) => !exportPathMap[route].page.match(API_ROUTE)
......
...@@ -13,6 +13,7 @@ module.exports = (phase) => { ...@@ -13,6 +13,7 @@ module.exports = (phase) => {
exportPathMap: function () { exportPathMap: function () {
return { return {
'/': { page: '/' }, '/': { page: '/' },
'/index': { page: '/index' },
'/about': { page: '/about' }, '/about': { page: '/about' },
'/button-link': { page: '/button-link' }, '/button-link': { page: '/button-link' },
'/hash-link': { page: '/hash-link' }, '/hash-link': { page: '/hash-link' },
......
...@@ -117,6 +117,20 @@ describe('Static Export', () => { ...@@ -117,6 +117,20 @@ describe('Static Export', () => {
).toBe(true) ).toBe(true)
}) })
it('should not duplicate /index with exportTrailingSlash', async () => {
expect(
await access(join(outdir, 'index/index.html'))
.then(() => true)
.catch(() => false)
).toBe(false)
expect(
await access(join(outdir, 'index.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
})
ssr(context) ssr(context)
browser(context) browser(context)
dev(devContext) dev(devContext)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment