Error AtlasError Documentation and Resolution

Next.js useRouter was used without a mounted Next router

NextRouter was not mounted

Next.js reported that useRouter was called outside the expected router context, which commonly happens in unit tests or when next/router is used inside the app directory.

NextRouter was not mountedruntime
NextRouter was not mounted
  • A component using useRouter was rendered in a test without a Next.js router context.
  • The app directory is importing useRouter from next/router instead of next/navigation.
  • A component is rendered outside a Next.js application shell.
  1. Mock next/router in tests or use a router mock library.
  2. In the app directory, migrate to the router hooks from next/navigation.
  3. If migrating pages code, consider next/compat/router where appropriate.
Next.js Docs: NextRouter was not mounted
NextRouter was not mounted: causes and fixes | Error Atlas