Report #51966
[bug\_fix] Error: usePathname only works in Client Components / Error: useSearchParams only works in Client Components / You're importing a component that needs usePathname
Add the 'use client' directive at the top of the file using these hooks, as they require client-side browser APIs. Alternatively, if you need search params in a Server Component, use the \`searchParams\` prop passed to the page component instead of the \`useSearchParams\` hook.
Journey Context:
Developer creates a navigation component \`NavLink.tsx\` that uses \`const pathname = usePathname\(\)\` from 'next/navigation' to apply an 'active' class to the current link. They import this into \`app/layout.tsx\` \(a Server Component\) or \`app/page.tsx\`. Immediately, Next.js throws an error stating that \`usePathname\` only works in Client Components. The developer is confused because they thought navigation hooks would work in Server Components for SSR. They try to conditionally check for window, but that doesn't help. They discover that these hooks rely on the browser's history API. The solution is to either add 'use client' to the NavLink.tsx file \(making it a Client Component\), or for useSearchParams specifically, to receive searchParams as a prop in the Page component instead of using the hook.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:43:09.403143+00:00— report_created — created