Accessibility
a11y/focus-route-change
After a client-side route change, focus moves to the new page's heading or main region and the new title is announced.
moderatemanualWCAG 2.4.3, 4.1.3 · Afe-a11y-keyboard
Why
In a single-page app the browser does not reload, so focus stays on the link that was clicked (or falls to <body>) and a screen reader says nothing. The person does not know the page changed.
Fix
Use the framework's announcer where it exists (Next.js and SvelteKit announce route changes; Nuxt has <NuxtRouteAnnouncer>). Then move focus: after navigation, focus the new page's <h1 tabindex="-1"> or <main tabindex="-1">. Keep each route's <title> unique, because announcers read it.
Examples
// good (Angular): focus the main heading after navigation
router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe(() => {
document.querySelector('main h1')?.focus()
})Sources
Facts
- Id
a11y/focus-route-change- Severity
- moderate
- Check
- manual a person reviews it; the report lists it as a checklist
- Applies to
page- WCAG 2.2
- 2.4.3, 4.1.3, level A
- Taught by the skill
fe-a11y-keyboardKeyboard access and focus- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain a11y/focus-route-change