SPAs leave focus where it was
Where focus should go after a client-side route change, what Next.js, Nuxt, React Router and SvelteKit do by default, and the twelve lines I would add to a Next.js app.
Single-page applications have a failure mode that multi-page sites don't have. The route changes, the page doesn't reload, and focus doesn't reset. The user is left on an element that may no longer exist, in front of content nobody announced.
Most frameworks leave it that way. SvelteKit is the exception.
What the browser used to do
On a multi-page site the browser handles this. Every page load resets focus, the screen reader announces the new title, and the user knows they've moved.
A single-page app breaks both. Routing happens in JavaScript, the DOM changes, and the browser never sees a navigation. Focus stays where it was, and the screen reader says nothing unless the framework added an announcer. A keyboard user's next Tab goes somewhere unrelated. A screen reader user gets no sign that anything changed. Someone using zoom is still looking at the old scroll position.
So where should focus go?
After a route change, focus goes to the new page's h1. Not the top of the document, not the skip link: the heading. Give it tabindex="-1" so it can take focus, and call .focus() once the route has committed.
Screen readers don't read a title change on their own, and they don't read the title when focus moves, so the new title needs an aria-live="polite" region or the framework's route announcer. Update document.title first, because that is what the announcer reads. Then scroll to the top, without an animation. The one exception to all of this: if the route change came from submitting a form inline, focus belongs on the confirmation.
For modals, use <dialog> with showModal() where you can. The browser makes the page behind it inert and, when it closes, returns focus to the element that had it before. A custom modal has to do the same three things by hand: move focus in, keep Tab from escaping to the page underneath, and put focus back on the opener when it closes. The last one is about five lines, a reference stored on open and restored on close, and it is the one most often missing. (A native modal dialog lets Tab reach the browser's own toolbar. That is on purpose.)
When content changes inside the page, focus mostly stays put. If new content replaces what the user is reading, announce it with aria-live. If it adds a toast or a notification, don't move focus there either. Nobody asked to be interrupted.
Framework defaults
Next.js 16, Nuxt 4, React Router and Vue Router still leave focus where it was after a route change. Next.js does announce the new page title by default, and Nuxt's starter template includes an announcer too. SvelteKit moves focus to the body, or to an element with autofocus, and announces the new title. Better than nothing. Still not the heading.
The browser now has the same behavior built in. The Navigation API, Baseline since early 2026, resets focus after a navigation it intercepts: to the first element with autofocus, otherwise to the body. So you could put autofocus on the h1. It also fires on the first page load, which is the one place you don't want it.
The framework authors have a point when they leave this to applications. Where focus should go depends on the page, and a generic default would hide real differences. In practice, "depends on the page" turns into "nobody does it."
Twelve lines for Next.js
In a Next.js app with the Pages Router it's twelve lines if you count the comment, and the comment is the line that matters most:
const router = useRouter();
const lastPath = useRef(router.asPath);
useEffect(() => {
// The first load is not a route change. Leave focus at the top there.
if (lastPath.current === router.asPath) return;
lastPath.current = router.asPath;
const heading = document.querySelector("h1");
if (heading) {
heading.setAttribute("tabindex", "-1");
heading.focus();
}
}, [router.asPath]);
It runs on every route, and two details in it are easy to get wrong. router.pathname is the route pattern: /blog/[slug] stays the same when you go from one post to the next, so the effect never fires. asPath is the real URL. And the ref skips the first page load, because moving focus to the h1 there jumps past the skip link and past the point where a screen reader starts reading.
The Pages Router already scrolls to the top and announces the title, so the effect only moves focus. With the App Router, the default since Next.js 13.4, put the same effect in a client component in the root layout and key it on usePathname() from next/navigation. That returns the real path, so the pattern trap doesn't exist there. It also doesn't fire when only the search params change.
You can go further: announce route changes through your own live region, move focus after a view transition's finished promise resolves, give each route its own focus target. The twelve lines come first.
Testing it with two pages
Open a page that links to another page of the same kind, two blog posts for example. Follow the link with Enter and press Tab once. Focus should land on the first link or control in the new page's content.
When it lands on something from the old page instead, the rest of the accessibility work on that page doesn't help much. No screen reader feature can tell the user where they are, because where they are is wrong.