get cuurent route name nextjs
To get the current route name in Next.js, you can follow these steps:
- Import the useRouter hook from the next/router module using the following code:
import { useRouter } from 'next/router';
- Call the useRouter hook to get the router object:
const router = useRouter();
- Access the current route name from the router object using the pathname property:
const currentRoute = router.pathname;
- 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.