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 Composable
The useRewriteURL composable for Vue 3 is designed to handle localized URL rewrites on the client side. It automatically corrects the browser's URL to its "pretty" localized version based on the user's current locale and the configuration in intlayer.config.ts.
It works by using window.history.replaceState, which avoids triggering unwanted Vue Router navigations.
Usage
Call the composable within your setup() function or <script setup>.
How it works
- Reactive Monitoring: The composable sets up a
watchon the user'slocale. - Rewrite Matching: Whenever the locale changes (or on mount), it checks if the current
window.location.pathnamematches a canonical route that has a prettier localized alias. - URL Correction: If a prettier alias is found, the composable calls
window.history.replaceStateto update the address bar without reloading the page or losing router state.
Why use it?
- SEO Optimization: Ensures search engines index the authoritative localized version of your URLs.
- Improved UX: Corrects manually entered URLs to reflect your preferred naming (e.g.,
/fr/a-proposinstead of/fr/about). - Low Overhead: Silently updates the URL without re-triggering component lifecycles or navigation guards.