Skip to content

Commit 30d0839

Browse files
committed
docs(book): added route announcer docs
1 parent 0938e97 commit 30d0839

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

docs/next/en-US/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@
7777
- [Subsequent Loads](/docs/advanced/subsequent-loads)
7878
- [Routing](/docs/advanced/routing)
7979
- [`define_app` in Detail](/docs/advanced/define_app)
80+
- [Route Announcer](/docs/advanced/route-announcer)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Route Announcer
2+
3+
Perseus uses a routing system separate to the browser's, as is typical of SPA and hybrid frameworks. However, while this means we download fewer resources for each page transition, this does mean that screen readers often won't know when a page change occurs. Of course, this is catastrophic for accessibility for vision-impaired users, so Perseus follows the example set by other frameworks and uses a *route announcer*. This is essentially just a glorified `<p>` element with the ID `__perseus_route_announcer` (so that you can make modifications to it imperatively if necessary) that's updated to tell the user the title of the current page.
4+
5+
When a user enters a session in your app (i.e. when they open your app from a link that's not inside your app), the browser can announce the page to any screen readers as usual, so the route announcer will start empty. However, on every subsequent page load in your app (all of which will use Perseus' custom router), the route announcer will be updated to declare the title of the page as it can figure it out. It does so in this order:
6+
7+
1. The `<title>` element of the page.
8+
2. The first `<h1>` element on the page.
9+
3. The page's URL (e.g. `/en-US/about`).
10+
11+
This prioritization is the same as used by NextJS, and Perseus' route announcer is heavily based on NextJS'.
12+
13+
Notably, the route announcer is invisible to the naked eye, and it will only 'appear' through a screen reader. This is achieved through some special styling optimized for displaying this kind of text, again inspired by NextJS' router announcer (which has been proven to work very well in long-term production).

0 commit comments

Comments
 (0)