Next.jsApp RouterError Fix2026 Updated
useRouter is Not a FunctionNext.js App Router — Fixed [2026]
Also covers: useRouter not working · router.query undefined · wrong import
January 20265 min readNext.js 13–15 · App Router
⚡ Quick Fix — Wrong Import
component.jsx
// ❌ WRONG — next/router is Pages Router only
import { useRouter } from 'next/router'
// ✅ CORRECT — App Router uses next/navigation
import { useRouter, usePathname, useParams, useSearchParams } from 'next/navigation'Why useRouter Errors in App Router
Error
TypeError: useRouter is not a function
at NavLink (components/NavLink.jsx:5)
# or:
Error: You're importing a component that needs useRouter.
This React hook only works in a client component.
Add the "use client" directive at the top of the file.Next.js 13 introduced the App Router with a completely different navigation system. The old next/router package (Pages Router) was replaced by next/navigation, and a single useRouter was split into four separate hooks with more focused APIs.
11 min
Import From next/navigation Not next/router
Wrong import — most common causecomponents/NavLink.jsx
'use client'
// ❌ WRONG — Pages Router import
import { useRouter } from 'next/router'
// ✅ CORRECT — App Router import
import { useRouter } from 'next/navigation'
export default function NavLink() {
const router = useRouter()
return (
<button onClick={() => router.push('/dashboard')}>
Go to Dashboard
</button>
)
}21 min
Add 'use client' Directive
Hooks require Client Componentcomponents/BackButton.jsx
'use client' // ← REQUIRED — must be first line
import { useRouter } from 'next/navigation'
export default function BackButton() {
const router = useRouter()
return <button onClick={() => router.back()}>Back</button>
}If you cannot add 'use client' to a component because it is a Server Component, extract only the navigation logic into a small Client Component wrapper.
31 min
usePathname for Current Route
Replaced router.pathnamecomponents/ActiveLink.jsx
'use client'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
export default function NavItem({ href, label }) {
const pathname = usePathname()
const isActive = pathname === href
return (
<Link
href={href}
className={isActive ? 'text-indigo-600 font-bold' : 'text-gray-600'}
>
{label}
</Link>
)
}41 min
useParams for Dynamic Route Params
Replaced router.query for [id] segmentsapp/blog/[slug]/page.jsx
// Server Component — params come as props
export default function BlogPost({ params }) {
const { slug } = params
return <h1>{slug}</h1>
}
// Client Component — use useParams hook
'use client'
import { useParams } from 'next/navigation'
export default function BlogPost() {
const params = useParams()
const { slug } = params // { slug: 'my-post-title' }
return <h1>{slug}</h1>
}52 min
useSearchParams for Query Strings
Replaced router.query for ?key=valuecomponents/SearchResults.jsx
'use client'
import { useSearchParams, useRouter } from 'next/navigation'
export default function SearchResults() {
const searchParams = useSearchParams()
const router = useRouter()
const query = searchParams.get('q') // ?q=nextjs → 'nextjs'
const page = searchParams.get('page') // ?page=2 → '2'
function goToPage(n) {
const params = new URLSearchParams(searchParams)
params.set('page', n.toString())
router.push(`?${params.toString()}`)
}
return <div>Searching for: {query} — Page {page}</div>
}Navigation Hook Cheat Sheet
| Pages Router (old) | App Router (new) | Purpose |
|---|---|---|
| router.push() | useRouter().push() | Navigate to route |
| router.pathname | usePathname() | Current URL path |
| router.query.id | useParams().id | Dynamic segment [id] |
| router.query.page | useSearchParams().get('page') | Query string ?page= |
| router.back() | useRouter().back() | Browser back |
Frequently Asked Questions
Why is useRouter not working in Next.js App Router?+−
In Next.js 13+ App Router, you must import useRouter from 'next/navigation' not 'next/router'. The next/router package is for the Pages Router only. Also, useRouter and all navigation hooks require the 'use client' directive.
What replaced useRouter in Next.js App Router?+−
The App Router splits useRouter into multiple hooks: useRouter() for programmatic navigation (push, replace, back), usePathname() for the current URL path, useParams() for dynamic route params, and useSearchParams() for query string params.
Can I use useRouter in a Server Component?+−
No. useRouter, usePathname, useParams, and useSearchParams are all Client Component hooks. They require 'use client' at the top of the file. In Server Components, access route params and search params through the component's props instead.
How do I navigate programmatically in Next.js App Router?+−
Import useRouter from 'next/navigation': const router = useRouter(); Then: router.push('/dashboard') to navigate, router.replace('/login') to replace history, router.back() to go back. This must be in a Client Component.
How do I get the current route in Next.js App Router?+−
Use usePathname from 'next/navigation': const pathname = usePathname(). This returns the current URL path like '/dashboard/settings'. For full URL including query string, use useSearchParams in combination.
useRouter().query is undefined in App Router — how to fix?+−
router.query does not exist in App Router. Use useParams() for dynamic segment params ([id], [slug]) and useSearchParams() for URL query parameters (?page=2). Both are in 'next/navigation'.
Need Expert Help?
We Build Production-Grade Next.js Apps
Softplix builds full-stack Next.js applications. Need help migrating from Pages Router to App Router? We can help.
Talk to an Engineer