Api

useScriptEventPage()

Access the current page title and path and trigger an event when they change.

Signature

function useScriptEventPage(onChange?: (payload: TrackedPage) => void): Ref<TrackedPage> {}

Where TrackedPage is { title?: string, path: string }.

Arguments

  • onChange (optional) - A function that Nuxt calls when the page title or path changes. Receives a single TrackedPage object.

Returns

A ref containing the current page title and path.

Examples

  • Track page changes.
<script setup lang="ts">
useScriptEventPage((ctx) => {
  console.log(ctx.title, ctx.path)
})
</script>