mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
57 lines
1.9 KiB
Markdown
57 lines
1.9 KiB
Markdown
---
|
|
title: '<NuxtRouteAnnouncer>'
|
|
description: 'Add a hidden element with the page title for assistive technologies.'
|
|
navigation:
|
|
badge: New
|
|
links:
|
|
- label: Source
|
|
icon: i-simple-icons-github
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-route-announcer.ts
|
|
size: xs
|
|
---
|
|
|
|
::important
|
|
This component is available in Nuxt v3.12+.
|
|
::
|
|
|
|
## Usage
|
|
|
|
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`layouts/`](/docs/guide/directory-structure/layouts) to enhance accessibility by informing assistive technologies about page's title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
|
|
```vue [app.vue]
|
|
<template>
|
|
<NuxtRouteAnnouncer />
|
|
<NuxtLayout>
|
|
<NuxtPage />
|
|
</NuxtLayout>
|
|
</template>
|
|
```
|
|
|
|
## Slots
|
|
|
|
You can pass custom HTML or components through the route announcer default slot.
|
|
|
|
```vue
|
|
<template>
|
|
<NuxtRouteAnnouncer>
|
|
<template #default="{ message }">
|
|
<p>{{ message }} was loaded.</p>
|
|
</template>
|
|
</NuxtRouteAnnouncer>
|
|
</template>
|
|
```
|
|
|
|
## Props
|
|
|
|
- `atomic`: Controls if screen readers announce only changes or the entire content. Set to true for full content readout on updates, false for changes only. (default `false`)
|
|
- `politeness`: Sets the urgency for screen reader announcements: `off` (disable the announcement), `polite` (waits for silence), or `assertive` (interrupts immediately). (default `polite`)
|
|
|
|
::callout
|
|
This component is optional. :br
|
|
To achieve full customization, you can implement your own one based on [its source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-route-announcer.ts).
|
|
::
|
|
|
|
::callout
|
|
You can hook into the underlying announcer instance using [the `useRouteAnnouncer` composable](/docs/api/composables/use-route-announcer), which allows you to set a custom announcement message.
|
|
::
|