שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Add usePathname utility"v10.0.023.6.2026
- "Init history"v8.2.022.6.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
Svelte Integration: usePathname Documentation
The usePathname function returns the current browser pathname with the locale segment stripped, as a Svelte Readable<string> store. 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 Svelte
העתקת הקוד ללוח
Overview
usePathname creates a Svelte readable store that reads window.location.pathname, strips the locale prefix via getPathWithoutLocale, and emits a new value whenever the browser fires a popstate event (back/forward navigation). Subscribe with the $ store syntax in components.
Usage
העתקת הקוד ללוח
Return Value
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| Type | Description |
|---|---|
Readable<string> | Svelte readable store containing the current pathname without the locale prefix. |
Behavior
- Locale stripping: Removes the leading locale segment (e.g.
/fr/dashboard→/dashboard). - Reactive: Emits a new value on every
popstateevent (browser back / forward navigation). - SSR-safe: Returns
""whenwindowis not available. - Cleanup: The
popstatelistener is removed automatically when the last subscriber unsubscribes.
Example
העתקת הקוד ללוח
