Next.js Discord

Discord Forum

Redirect to relative path with query param using middleware

Unanswered
Manchester Terrier posted this in #help-forum
Open in Discord
Avatar
Manchester TerrierOP
Hi, I am using NextJs 13.4.5 and I am trying to redirect to a relative path with query param given to middleware but the redirect does not seem to happen

In the middleware, I am calling return NextResponse.redirect(url) with a url that uses a relative path submitted from a server component, I am calling the following snippet:
The relative path is given as a param of "redirectRelativePath"
import { redirect } from "next/navigation"
//...
const url =
  "/bugTracker/login?redirectRelativePath=" +
  "/bugTracker/login?emailNotConfirmed=Y"
redirect(url)


I am looking to just redirect from /bugTracker/login to /bugTracker/login?emailNotConfirmed=Y

I am new to using redirect and I was wondering if there is a better method to redirect to a url that has a path and query param, when calling redirect(url) from a server component.

Thank you!
:blob_help:
Image

0 Replies