mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
607ff2b322
* Update to process redirects/rewrites for _next/data * correct matched-path resolving with middleware * Add next-data header * migrate middleware tests * lint-fix * update error case * update test case * Handle additional resolving cases and add more tests * update test from merge * fix test * rm .only * apply changes from review * ensure _next/data resolving does not apply without middleware
25 lines
575 B
JavaScript
25 lines
575 B
JavaScript
import { NextResponse } from 'next/server'
|
|
|
|
export async function middleware(request) {
|
|
const url = request.nextUrl
|
|
|
|
if (
|
|
request.method === 'HEAD' &&
|
|
url.basePath === '/root' &&
|
|
url.pathname === '/redirect-me-to-about'
|
|
) {
|
|
url.pathname = '/about'
|
|
return NextResponse.redirect(url)
|
|
}
|
|
|
|
if (url.pathname === '/redirect-with-basepath' && !url.basePath) {
|
|
url.basePath = '/root'
|
|
return NextResponse.redirect(url)
|
|
}
|
|
|
|
if (url.pathname === '/redirect-with-basepath') {
|
|
url.pathname = '/about'
|
|
return NextResponse.rewrite(url)
|
|
}
|
|
}
|