useRequestURL()
Returns a URL object for the current request, on server and client.
Syntax
const url = useRequestURL() Returns
URL — A WHATWG URL with origin, pathname, searchParams, host.
Examples
<script setup lang="ts">
const url = useRequestURL()
useHead({
link: [{ rel: 'canonical', href: url.href }],
})
</script>
<script setup lang="ts">
const url = useRequestURL()
const isPreview = url.searchParams.get('preview') === '1'
</script>
Notes
On the server the URL is derived from the request; on the client it
comes from `window.location`. Useful for generating absolute canonical
links and Open Graph URLs that must be correct during SSR.