Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Next.js throws NEXT_REDIRECT and the redirect never happens

ErrorNEXT_REDIRECT

Short answer

redirect() works by throwing a NEXT_REDIRECT error that Next.js catches itself. If your own try/catch catches it first, the redirect is swallowed and you see the error. Call redirect() outside the try block. Inside a client event handler use the useRouter hook instead.

  • Applies to Next.js 15, Next.js 16, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find the redirect() call and check whether it sits inside a try block, or inside an onClick or onSubmit handler.

    grep -rn "redirect(" app/ --include=*.ts --include=*.tsx
  2. 2Match what you see, then jump to its fix

    1. 1The catch block runs and logs NEXT_REDIRECTredirect() is called inside a try/catchFix
    2. 2The error appears after a click, in a Client Componentredirect() is called from a client event handlerFix

What does the error look like?

  • NEXT_REDIRECT

Cause 1 of 2

redirect() is called inside a try/catch

1Check

redirect() throws an error to stop rendering. A catch block around it receives that error before Next.js can handle it.

try {
  await saveUser(data)
  redirect("/dashboard") // caught below
} catch (e) {
  console.error(e) // prints NEXT_REDIRECT
}

2Fix

Do the risky work inside try/catch and call redirect() after it, outside the block.

let ok = false
try {
  await saveUser(data)
  ok = true
} catch (e) {
  console.error(e)
}
if (ok) redirect("/dashboard")

3Verify

Call the route again. The response should be a 307 with a Location header, and the catch block should stay silent.

curl -i -X POST http://localhost:3000/api/save

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 2

redirect() is called from a client event handler

1Check

In a Client Component, redirect() is allowed while rendering but not inside an event handler such as onClick.

grep -rn "onClick\|onSubmit" app/ --include=*.tsx

2Fix

Use the useRouter hook in the handler, or call a Server Action that runs redirect().

'use client'
import { useRouter } from 'next/navigation'

export function Go() {
  const router = useRouter()
  return <button onClick={() => router.push('/dashboard')}>Go</button>
}

3Verify

Click the button and check the URL changes.

# open the page in the browser and click the button

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Treat redirect() like return: it ends the function, so put it last.
  • Keep client navigation in useRouter and server navigation in redirect().

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.