Good to know:
Reading the current URL from a Server Component is not supported. This design is intentional to support layout state being preserved across page navigations.
Compatibility mode:
usePathname can return null when a fallback route is being rendered or when a pages directory page has been automatically statically optimized by Next.js and the router is not ready.
Next.js will automatically update your types if it detects both an app and pages directory in your project.
Parameters
 const pathname = usePathname()
usePathname does not take any parameters.
Returns
usePathname returns a string of the current URL's pathname. For example:
URLReturned value/'/'/dashboard'/dashboard'/dashboard?v=2'/dashboard'/blog/hello-world'/blog/hello-world'
Examples
Do something in response to a route change
app/example-client-component.tsx 'use client'
 
import { usePathname, useSearchParams } from 'next/navigation'