Accessible Routing

Accessible client-side routing preserves meaningful document context and communicates route changes to assistive technology. A robust implementation updates the URL and rendered content, then deliberately manages focus and announces the new route without causing duplicate or confusing speech.

In a traditional page navigation, the browser loads a new document and assistive technologies generally receive a natural document-context change. A single-page application (SPA) instead changes application state while keeping the same document, so developers must recreate important parts of that navigation experience.

After a route change, the new page should expose an appropriate heading and move keyboard focus to a predictable location, commonly a main-content container or the page heading. The destination should use `tabindex="-1"` when necessary so it can receive programmatic focus without becoming part of the normal Tab sequence.

A route-change announcement can also be provided through an `aria-live` region. The announcement should be concise and should not replace actual focus management or a meaningful document structure. In many applications, the live region announces the destination while focus moves to the new content.

Routing must also preserve normal browser behavior: links should remain real links, URLs should update, browser Back and Forward should work, and focus should not be moved unnecessarily when navigation is prevented. Framework routing APIs can automate some of this, but the application still needs to verify the resulting behavior with keyboard navigation and assistive technology.

Performance and accessibility interact here because route transitions should not leave users waiting without feedback. If content loads asynchronously, the application should expose an appropriate loading state and then establish the final destination context when the route is ready.

Key points

Interview questions

Why does client-side routing create an accessibility problem in an SPA?

A client-side route change usually updates rendered content without replacing the browser document. As a result, keyboard focus may remain on the old navigation link and a screen reader may not automatically understand that the user has reached a new page. The application should establish a predictable destination context, typically by focusing the new main content or heading. A concise route announcement can provide additional feedback.

How would you implement focus management after a route change?

I would identify a stable element representing the new page, such as the main container or primary heading. After the route's content is available, I would call `focus()` on that element and give it `tabindex="-1"` if it is not normally focusable. I would avoid stealing focus during unrelated state updates and make sure the behavior also works with browser Back and Forward navigation. I would then test the flow with keyboard-only navigation and a screen reader.

What role does an `aria-live` region play in accessible routing?

An `aria-live` region lets assistive technology receive a textual update when its content changes. A routing implementation can use it to announce the new page or section after navigation. It should contain concise information rather than an entire page of text. It complements focus management rather than replacing it, because an announcement does not determine where keyboard interaction continues.

What accessibility behavior should a router preserve besides announcing route changes?

The router should preserve normal web navigation semantics wherever possible. Navigation should remain keyboard accessible, URLs should represent the current location, and Back and Forward should restore the appropriate application state and content. Links should behave like links rather than being replaced unnecessarily with generic clickable elements. The implementation should also account for loading states and focus restoration when navigation is asynchronous.

How would you test an accessible SPA route transition?

I would first test with only the keyboard, checking that focus has a predictable destination and that Tab order remains sensible. Then I would use a screen reader to verify that the new page context is discoverable and that announcements are concise and not duplicated. I would test direct links, internal links, Back and Forward, refreshes, slow route data, and error states. Automated accessibility checks can supplement these tests but cannot replace interaction testing.