0Pricing
Web Accessibility Academy · レッスン

ページを再読み込みせずにルートを変更する

ルート変更時にナビゲーションを通知し、フォーカスを移動します。

「ページを再読み込みせずにルートを変更する」はCoddyKit上の無料Web Accessibility Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb Accessibility Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web Accessibility Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

The Silent Navigation Problem

In a SPA, clicking a link swaps content without a full reload. To a screen reader, nothing seems to happen, so it stays silent about the new page. 🤫

Why Full Reloads Were Easy

A real page load resets focus and makes the screen reader read the new title. Client-side routing skips all of that, so you must recreate those cues yourself.

Update the Document Title

On every route change, set document.title to match the new view. Many screen readers read the title when it changes, giving users their bearings.

useEffect(() => {
  document.title = 'Settings - MyApp';
}, [location.pathname]);

Move Focus on Navigation

After routing, send focus to the top of the new content, usually the main heading. This tells keyboard and screen reader users the page has changed.

Focus the Heading or Main

Give the target a tabindex of -1 so it can receive focus by script without joining the tab order. Then call .focus() on it after the route updates.

<h1 tabindex="-1" ref={headingRef}>Settings</h1>

Announce With a Live Region

An alternative is a visually hidden live region that you fill with text like Navigated to Settings. The screen reader speaks it without moving focus.

<div aria-live="polite" className="sr-only">{message}</div>

Pick One Strategy, Not Both

Moving focus and announcing in a live region both work. Doing both at once can cause double announcements, so choose one approach per app and stay consistent.

Timing Matters

Run your focus or announcement after the new view renders. In React, an effect that depends on the route path fires once the DOM is updated.

Do Not Yank Focus Mid-Task

Only move focus on a genuine route change, not on minor in-place updates. Stealing focus while someone is mid-action is jarring and confusing.

Router Libraries Can Help

Some routers expose hooks for route changes. React Router gives you useLocation, so an effect can react every time the path actually changes.

const location = useLocation();
useEffect(() => focusMain(), [location.pathname]);

Test It Like a User

Turn on a screen reader, click through your nav, and listen. If route changes are announced and focus lands sensibly, your SPA navigation is accessible.

Quick Check

A screen reader user clicks a SPA link but hears nothing change. What is the most likely cause?

Recap: Announce the Route

SPA navigation is invisible until you make it heard. Update the title, then move focus or use a live region so everyone knows the page changed. ✅

よくある質問

「ページを再読み込みせずにルートを変更する」レッスンは無料ですか?

はい。「ページを再読み込みせずにルートを変更する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web Accessibility Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web Accessibility Academyコースには全4レッスンが含まれています。

「ページを再読み込みせずにルートを変更する」で何を学びますか?

ルート変更時にナビゲーションを通知し、フォーカスを移動します。 ブラウザで直接実行するハンズオンコードでWeb Accessibility Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web Accessibility Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb Accessibility Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「ページを再読み込みせずにルートを変更する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb Accessibility Academyレッスンでコードを書いて実行できますか?

はい。すべてのWeb Accessibility Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ページを再読み込みせずにルートを変更する
  2. RefsとuseEffectでフォーカスを管理する
  3. Fragment、Portal、そしてDOM順序の落とし穴
  4. jsx-a11yとコンポーネントレベルのガードレール
← Web Accessibility Academyに戻る