Unverified Commit bd24b70d authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Fix trailing slash handling in exporting pages with getStaticPaths (#14620)

Fixes https://github.com/vercel/next.js/issues/14573
parent 3909c76c
......@@ -24,6 +24,7 @@ import { findPageFile } from '../server/lib/find-page-file'
import { GetStaticPaths } from 'next/types'
import { denormalizePagePath } from '../next-server/server/normalize-page-path'
import { BuildManifest } from '../next-server/server/get-page-files'
import { normalizeTrailingSlash } from '../next-server/lib/router/normalize-trailing-slash'
const fileGzipStats: { [k: string]: Promise<number> } = {}
const fsStatGzip = (file: string) => {
......@@ -573,6 +574,7 @@ export async function buildStaticPaths(
// For a string-provided path, we must make sure it matches the dynamic
// route.
if (typeof entry === 'string') {
entry = normalizeTrailingSlash(entry)
const result = _routeMatcher(entry)
if (!result) {
throw new Error(
......
export async function getStaticPaths() {
return {
paths: ['/gssp/foo/'],
fallback: false,
}
}
export async function getStaticProps({ params }) {
return { props: params }
}
export default function Page({ slug }) {
return `Hello ${slug}`
}
......@@ -103,6 +103,20 @@ describe('Static Export', () => {
).toBe(true)
})
it('should handle trailing slash in getStaticPaths', async () => {
expect(
await access(join(outdir, 'gssp/foo/index.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
expect(
await access(join(outNoTrailSlash, 'gssp/foo.html'))
.then(() => true)
.catch(() => false)
).toBe(true)
})
it('should only output 404.html without exportTrailingSlash', async () => {
expect(
await access(join(outNoTrailSlash, '404/index.html'))
......
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