-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmiddleware.ts
More file actions
20 lines (17 loc) · 704 Bytes
/
middleware.ts
File metadata and controls
20 lines (17 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// eslint-disable-next-line import/no-unresolved
import { NextRequest, NextResponse } from 'next/server';
import { locales } from 'nextra/locales';
const redirects: Record<string, string> = {
'/examples/react/ipfs-playback': '/examples/react/dstorage-playback',
};
export function middleware(request: NextRequest) {
// Handle redirect in `_middleware.ts` because of bug using `next.config.js`
// https://github.com/shuding/nextra/issues/384
if (request.nextUrl.pathname in redirects) {
const url = request.nextUrl.clone();
const pathname = redirects[request.nextUrl.pathname] ?? '/';
url.pathname = pathname;
return NextResponse.redirect(url);
}
return locales(request);
}