get cuurent route name nextjs

To get the current route name in Next.js, you can follow these steps:

  1. Import the useRouter hook from the next/router module using the following code:
import { useRouter } from 'next/router';
  1. Call the useRouter hook to get the router object:
const router = useRouter();
  1. Access the current route name from the router object using the pathname property:
const currentRoute = router.pathname;
  1. The currentRoute variable will now hold the name of the current route in Next.js.

That's it! By following these steps, you can get the current route name in Next.js.