Skip to content

Commit

Permalink
fix: bug of relative urls
Browse files Browse the repository at this point in the history
  • Loading branch information
aiji42 committed May 2, 2022
1 parent ecbcf5b commit 8ac6aa4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/handle-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ export const handleFallback = (
): ReturnType<NextMiddleware> => {
if (typeof fallback === 'function') return fallback(request, event)
if (request.preflight) return new NextResponse(null)
if (fallback.type === 'rewrite')
return NextResponse.rewrite(fallback.destination)
if (fallback.type === 'rewrite') {
const url = request.nextUrl.clone()
url.pathname = fallback.destination
return NextResponse.rewrite(url)
}

if (request.nextUrl.pathname !== fallback.destination)
return NextResponse.redirect(fallback.destination, fallback.statusCode)
if (request.nextUrl.pathname !== fallback.destination) {
const url = request.nextUrl.clone()
url.pathname = fallback.destination
return NextResponse.redirect(url, fallback.statusCode)
}
}

0 comments on commit 8ac6aa4

Please sign in to comment.