Creation:2025-08-23Last update:2025-08-23
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Edit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
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.
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.