Skip to content

Commit c85fbb3

Browse files
authored
fix/site: Return HTTP 404 instead of 200 for unknown pages (#1860)
1 parent e1dc366 commit c85fbb3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/app/[...slug]/page.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import {getMDXComponent} from 'next-contentlayer/hooks';
99
import {notFound} from 'next/navigation';
1010
import {Suspense} from 'react';
1111

12-
export const maxDuration = 300;
12+
// Every page is enumerated by generateStaticParams. Reject unknown slugs at the
13+
// router so the site returns a real HTTP 404. Without this, notFound() runs
14+
// inside the root layout's <Suspense> after the response has started streaming,
15+
// and the not-found page is served with status 200.
16+
export const dynamicParams = false;
1317

1418
export const generateStaticParams = async () => {
15-
return allPosts.map(post => ({
16-
params: {slug: post._raw.flattenedPath.split('/')}
17-
}));
19+
return allPosts
20+
// The root document is served by app/page.tsx, not this catch-all route.
21+
.filter(post => post._raw.flattenedPath !== '')
22+
.map(post => ({slug: post._raw.flattenedPath.split('/')}));
1823
};
1924

2025
export const generateMetadata = ({params}: Props) => {

0 commit comments

Comments
 (0)