Since Next.js 13.4, you can use the following hooks from the next/navigation module:
- useRouter,
- useSearchParams,
- usePathname,
- useParams.
These hooks replace the functionality available in the useRouter hook in the next/hook module, however, the behavior is distinct.
This codemod allows you to migrate the useRouter hook to the new useRouter hook imported from next/navigation. This includes all usages of the useRouter hook which may be replaced with useSearchParams and usePathname.
Example
Before
tsx
After
tsx