NextResponse redirect with Header Prop #51232
-
How would one issue a redirect within middleware, while also setting custom headers? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
This is one of a way to do it. import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
if (request.nextUrl.pathname === '/') {
const response = NextResponse.redirect(new URL('/test', request.nextUrl))
response.headers.set('some-header', 'hello')
return response
}
} Reference |
Beta Was this translation helpful? Give feedback.
-
Is anyone else experiencing this issue? It's causing significant problems. I've been investigating and have formed some theories about what might be happening: Here's an example to help explain:
This is just my understanding based on what I've observed. If anyone has experienced something similar or has more insights, please share. |
Beta Was this translation helpful? Give feedback.
-
or just simply
|
Beta Was this translation helpful? Give feedback.
This is one of a way to do it.
Reference