NextJS docs say middleware can delete query params, but it does not work...
Unanswered
Oak rough bulletgall wasp posted this in #help-forum
Oak rough bulletgall waspOP
I found this article
https://nextjs.org/docs/messages/deleting-query-params-in-middlewares
Which makes no sense to me how it is written, "and thus the warning." -- yet there is no warning displayed in their code example, but rather saying
I now have the following middleware function:
I see
https://nextjs.org/docs/messages/deleting-query-params-in-middlewares
Which makes no sense to me how it is written, "and thus the warning." -- yet there is no warning displayed in their code example, but rather saying
.delete is now possible with a party emoji---- sooooo....I now have the following middleware function:
export function middleware(request: NextRequest) {
const nextUrl = request.nextUrl
const redirect = nextUrl.searchParams.get('redirect_url')
if (redirect) {
nextUrl.searchParams.delete('redirect_url')
const next = NextResponse.rewrite(nextUrl)
console.log('*** deleted! ***')
return next
}
return NextResponse.next()
}I see
*** deleted! *** in my server log, but the url still contains the query string param... What am I doing wrong?