Skip to content

Commit 4766281

Browse files
GeneAIGeneAI
authored andcommitted
fix: Add Next.js middleware to enforce trailing slash for framework-docs
1 parent 994d5ad commit 4766281

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

website/middleware.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NextResponse } from 'next/server';
2+
import type { NextRequest } from 'next/server';
3+
4+
export function middleware(request: NextRequest) {
5+
const pathname = request.nextUrl.pathname;
6+
7+
// Add trailing slash to framework-docs paths (except for files with extensions)
8+
if (pathname.startsWith('/framework-docs/') &&
9+
!pathname.endsWith('/') &&
10+
!pathname.match(/\.[a-zA-Z0-9]+$/)) {
11+
const url = request.nextUrl.clone();
12+
url.pathname = pathname + '/';
13+
return NextResponse.redirect(url, 308);
14+
}
15+
16+
return NextResponse.next();
17+
}
18+
19+
export const config = {
20+
matcher: '/framework-docs/:path*',
21+
};

0 commit comments

Comments
 (0)