useUrl hook retrieves the current URL in a server or client component.
Example codeAnchor link to section titled "Example code"
Subscribing to the current URL valueAnchor link to section titled "Subscribing to the current URL value"
In client components, you can subscribe to the current value of the URL:
The value of the URL will change immediately, but the page transition might not yet be completed. If you want to wait until the page is completely transitioned, then use the
pending server state hook value:
Return valueAnchor link to section titled "Return value"
useUrl hook returns a URL object with the current URL.