nextjs
migration_error
ai_generated
true
Error: NextRouter was not mounted
ID: nextjs/next-router-app-dir
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 14 | active | — | — | — |
Root Cause
Using next/router in App Router. App Router uses next/navigation instead.
genericWorkarounds
-
95% success Replace next/router with next/navigation
// Old: import { useRouter } from 'next/router' // New: import { useRouter } from 'next/navigation' -
92% success Replace router.query with useSearchParams() and useParams()
import { useSearchParams, useParams } from 'next/navigation';Sources: https://nextjs.org/docs/app/api-reference/functions/use-search-params
Dead Ends
Common approaches that don't work:
-
Wrap with RouterContext.Provider
85% fail
Hack that doesn't work — App Router has a different router
-
Move the file to pages/ directory
60% fail
Defeats the purpose of migrating to App Router
Error Chain
Frequently confused with: