useUrl
The useUrl
hook retrieves the current URL in a server or client component.
Example code
Anchor link to section titled "Example code"
Subscribing to the current URL value
Anchor 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 value
Anchor link to section titled "Return value"The useUrl
hook returns a URL object with the current URL.