Next.js Discord

Discord Forum

how to redirect from an API route in next 13 ?

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
{ redirect } from next/navigation is not working for my use
route path: /api/process/route.ts

redirect('http://localhost:3000/dashboard/');
throws Error: NEXT_REDIRECT

12 Replies

You can only use it in sever components and server actions, for route handlers, use NextResponse or client side navigation instead
Cape lionOP
is this a running bug atm ?
coz the docs say it should work for route handlers
even NextResponse.redirect() is not working for me
Because it doesn't work for POST route handlers
currently only available for GET, and I can confirm NextResponse.redirect works since I'm using it in my projects
But client-side navigation usually makes more sense unless you're implementing oauth2 flow
Cape lionOP
yeah right @fuma i'm using oauth flow
got it thanks a ton ! it worked for me now, was getting some error previously could be making a mistake
@fuma But client-side navigation usually makes more sense unless you're implementing oauth2 flow
Cape lionOP
oauth is the only reason i'd search for something like this, i am always the proponent of client side redirects