שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Add usePathname utility"v10.0.023.6.2026
- "Init history"v8.2.022.6.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
Preact Integration: usePathname Hook Documentation
The usePathname hook returns the current browser pathname with the locale segment stripped. It is useful for building locale-aware navigation (for example, determining which nav item is active) without having to manually remove the locale prefix.
Importing usePathname in Preact
העתקת הקוד ללוח
Overview
usePathname reads window.location.pathname, strips the locale prefix via getPathWithoutLocale, and re-renders the component whenever the browser fires a popstate event (back/forward navigation). It returns an empty string during server-side rendering.
Usage
העתקת הקוד ללוח
Return Value
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| Type | Description |
|---|---|
string | The current pathname without the locale prefix. Empty string during server-side rendering. |
Behavior
- Locale stripping: Removes the leading locale segment (e.g.
/en/dashboard→/dashboard). - Reactive: Updates automatically on
popstateevents (browser back / forward navigation). - SSR-safe: Returns
""whenwindowis not available. - Cleanup: The
popstatelistener is removed automatically when the component unmounts.
Example
העתקת הקוד ללוח
