Next.js Discord

Discord Forum

is it possible to "push" users to different pages in api routes?

Answered
Pacific herring posted this in #help-forum
Open in Discord
Pacific herringOP
For example in my POST function i'd need to redirect my user to /home
Answered by Sun bear
Are you looking for something like Next's redirect function: https://nextjs.org/docs/app/api-reference/functions/redirect ? Redirecting the users to the desired page once the api call returns. I think that you could also return res.redirect() directly from the API route to return a NextResponse with a redirect set, mentioned towards the bottom of the page I linked earlier.
View full answer

1 Reply

Sun bear
Are you looking for something like Next's redirect function: https://nextjs.org/docs/app/api-reference/functions/redirect ? Redirecting the users to the desired page once the api call returns. I think that you could also return res.redirect() directly from the API route to return a NextResponse with a redirect set, mentioned towards the bottom of the page I linked earlier.
Answer