0Pricing
Web Accessibility Academy · درس

تغيير المسارات دون إعادة تحميل الصفحات

أعلنوا عن التنقل وانقلوا التركيز عند تغيير المسار

تغيير المسارات دون إعادة تحميل الصفحات درس مجاني في Web Accessibility Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Web Accessibility Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.

ماذا ستتعلم في «تغيير المسارات دون إعادة تحميل الصفحات»؟

أعلنوا عن التنقل وانقلوا التركيز عند تغيير المسار تتمرن على Web Accessibility Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Web Accessibility Academy؟

لا تُشترط خبرة سابقة. Web Accessibility Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «تغيير المسارات دون إعادة تحميل الصفحات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Web Accessibility Academy هذا؟

نعم. كل درس في Web Accessibility Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تغيير المسارات دون إعادة تحميل الصفحات
  2. إدارة التركيز باستخدام Refs وuseEffect
  3. Fragments وPortals وفخ ترتيب DOM
  4. jsx-a11y وحواجز الأمان على مستوى المكوّنات
← العودة إلى Web Accessibility Academy