מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
useRewriteURL Hook
The useRewriteURL hook for SolidJS 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.
By using window.history.replaceState, it avoids redundant Solid Router navigations.
Usage
Call the hook within a component that is part of your application.
tsx
העתקת קוד
העתקת הקוד ללוח
How it works
- Detection: The hook uses
createEffectto monitor changes in the reactivelocale(). - Matching: It identifies if the current
window.location.pathnamecorresponds to a canonical route that has a prettier localized alias for the current language. - URL Correction: If a prettier alias is found, the hook calls
window.history.replaceStateto update the address bar without affecting the internal navigation state or causing component re-renders.
Why use it?
- Authoritative URLs: Enforces a single URL for each localized version of your content, which is crucial for SEO.
- Developer Convenience: Allows you to keep your internal route definitions canonical while exposing user-friendly, localized paths to the outside world.
- Consistency: Corrects URLs when users manually type a path that doesn't follow your preferred localization rules.
