מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
useRewriteURL Hook
The useRewriteURL hook for Svelte is designed to manage localized URL rewrites on the client side. It automatically corrects the browser's URL to its "pretty" localized version based on the current locale and the configuration in intlayer.config.ts.
It updates the URL silently using window.history.replaceState, avoiding full SvelteKit navigations.
Usage
Call the hook within a Svelte component.
svelte
העתקת קוד
העתקת הקוד ללוח
How it works
- Reactive Updates: The hook subscribes to the Intlayer
localestore. - Detection: Whenever the locale changes (or on mount), it calculates if the current
window.location.pathnamehas a prettier localized alias defined in your rewrite rules. - URL Correction: If a prettier path is found, the hook calls
window.history.replaceStateto update the address bar without a full page reload or triggering SvelteKit navigation logic.
Why use it?
- SEO Best Practices: Ensures search engines index only the pretty, localized version of your URLs.
- Improved UX: Corrects manually entered URLs to reflect your preferred naming structure.
- Silent Updates: Modifies the address bar without affecting the component tree or navigation history.
