Next.js Discord

Discord Forum

How do I redirect a user using router.push and query params?

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
There is a form inside my page with the use client at the top of the file and I check if the user has an account or not. If there is no account, then I want to redirect them to /signup with a query param of email. I added:
router.push(`/signup?email=${email}`)

but apparently this query never arrives at the signup. is there a specific reason or a specific thing that I need to do to make this work?

5 Replies

@American black bear There is a form inside my page with the `use client` at the top of the file and I check if the user has an account or not. If there is no account, then I want to redirect them to `/signup` with a query param of `email`. I added: js router.push(`/signup?email=${email}`) but apparently this query never arrives at the signup. is there a specific reason or a specific thing that I need to do to make this work?
You shouldn't trust your client, that he will be redirected to the signup page. Instead: create a middleware and check if the user has an account there. Then you can use the redirect function, to redirect the user to the specific location and of course also with a query param, when you using the middleware
American black bearOP
I am have an endpoint that checks if the user has an account
but actually the problem was the middleware
the i18n was cleaning up the route and removing the query param
ah ok