Skip to content

Commit 4e9157c

Browse files
GeneAIGeneAI
authored andcommitted
fix: Force trailing slashes at all levels for MkDocs CSS compatibility
- Add trailingSlash: true to vercel.json for edge-level enforcement - Add explicit redirect rule in vercel.json for framework-docs paths - Set trailingSlash: true in next.config.ts - Update middleware to handle all framework-docs paths consistently
1 parent 5526528 commit 4e9157c

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

website/middleware.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@ import type { NextRequest } from 'next/server';
44
export function middleware(request: NextRequest) {
55
const pathname = request.nextUrl.pathname;
66

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);
7+
// Handle framework-docs paths - ensure trailing slash for MkDocs relative paths
8+
if (pathname.startsWith('/framework-docs')) {
9+
// Skip files with extensions (CSS, JS, images, etc.)
10+
if (pathname.match(/\.[a-zA-Z0-9]+$/)) {
11+
return NextResponse.next();
12+
}
13+
14+
// Add trailing slash if missing
15+
if (!pathname.endsWith('/')) {
16+
const url = request.nextUrl.clone();
17+
url.pathname = pathname + '/';
18+
return NextResponse.redirect(url, 308);
19+
}
1420
}
1521

1622
return NextResponse.next();
1723
}
1824

1925
export const config = {
20-
matcher: '/framework-docs/:path*',
26+
// Match all framework-docs paths
27+
matcher: [
28+
'/framework-docs',
29+
'/framework-docs/:path*',
30+
],
2131
};

website/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "path";
44
const nextConfig: NextConfig = {
55
output: 'standalone',
66
outputFileTracingRoot: path.join(__dirname, './'),
7-
skipTrailingSlashRedirect: true, // Don't auto-redirect trailing slashes - let middleware handle it
7+
trailingSlash: true, // Force trailing slashes for MkDocs compatibility
88
eslint: {
99
// Only run ESLint on these directories during production builds
1010
dirs: ['app'],

website/vercel.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"trailingSlash": true,
3+
"redirects": [
4+
{
5+
"source": "/framework-docs/:path((?!.*\\.).*[^/])",
6+
"destination": "/framework-docs/:path/",
7+
"permanent": true
8+
}
9+
],
210
"headers": [
311
{
412
"source": "/framework-docs/(.*)",

0 commit comments

Comments
 (0)