Report #104259
[bug\_fix] Next.js App Router: "Error: useRouter\(\) is not supported in server components. Add 'use client' at the top of the file to use this hook."
Move the component using \`useRouter\` into a client component by adding \`'use client'\` directive, or use the \`next/navigation\` \`redirect\` function \(which works in server components\) if you only need to redirect.
Journey Context:
I was building a server-side rendered page that needed to programmatically navigate after a form submission. I imported \`useRouter\` from \`next/navigation\` and called \`router.push\('/dashboard'\)\` inside a server component. The build threw the error. I tried using \`next/router\` instead, but that also failed. I then read the docs and learned that \`useRouter\` is a client-side hook. For server components, the recommended approach is to use the \`redirect\` function from \`next/navigation\` for redirects, or use a client component for other router interactions. I refactored my form handler into a client component with \`'use client'\` and passed the router from there. The fix worked immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:08:02.707129+00:00— report_created — created