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
The content of this page was translated using an AI.
See the last version of the original content in EnglishEdit 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 localised URL rewrites on the client-side. It automatically corrects the browser's URL to its "pretty" localised version based on the current locale and the configuration in intlayer.config.ts.
By using window.history.replaceState, it avoids unnecessary 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 localised 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 localised version of your content, which is crucial for search engine optimisation (SEO).
- Developer Convenience: Allows you to keep your internal route definitions canonical while exposing user-friendly, localised paths to the outside world.
- Consistency: Corrects URLs when users manually type a path that doesn't follow your preferred localisation rules.