C

next/13/replace-next-router

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

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

Ready to contribute?

Build your own codemod and share it with the community.