searchParams undefined only after passing middleware.
Unanswered
SaberV posted this in #help-forum
SaberVOP
Hello, i would like an advice regarding an issue in which:
({ params, searchParams }) is not included (return undefined) when it has middleware with NextResponse.rewrite(req.nextUrl), any idea why?
- If middleware is disabled, i can access the searchParams
- req.nextUrl includes all, even searchParams object
- localhost:3000/admin/users/list?page=1 is link example
- page.tsx is confirmed Server Component
- changing to NextResponse.next or .redirect produce the same behaviour
({ params, searchParams }) is not included (return undefined) when it has middleware with NextResponse.rewrite(req.nextUrl), any idea why?
- If middleware is disabled, i can access the searchParams
- req.nextUrl includes all, even searchParams object
- localhost:3000/admin/users/list?page=1 is link example
- page.tsx is confirmed Server Component
- changing to NextResponse.next or .redirect produce the same behaviour
import all relevant
export default withAuth(
function middleware(req) {
if (req.nextUrl.pathname.startsWith('/admin')) {
return NextResponse.rewrite(req.nextUrl) //(new URL(req.nextUrl.pathname, req.url)
} else {
return NextResponse.rewrite(new URL('/', req.url))
}
},
{
callbacks: {
authorized: ({ token }) => token
},
}
)
export const config = { matcher: ["/admin/:path*"] }