Api
useScriptEventPage()
Track the current page title and full route path, with an optional client-side callback.
Signature
function useScriptEventPage(onChange?: (payload: TrackedPage) => void): Ref<TrackedPage> {}
TrackedPage is { title?: string, path: string }.
Arguments
onChange(optional): Called in the browser after apage:finishhook when the title or path differs from the last emitted value. It is not called during SSR.
If you register the composable before the initial page:finish hook, as you normally would in app.vue, the callback receives the first hydrated page as well as later navigations. A composable created after that hook waits for the next page finish; it does not backfill a callback.
Returns
A ref containing the current page title and full path, including its query string and hash. During SSR, title starts as an empty string because the document has not rendered yet.
Example
Log each page change:
<script setup lang="ts">
useScriptEventPage((ctx) => {
console.log(ctx.title, ctx.path)
})
</script>