מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2025-08-23
העתקה
העתקת ה-Markdown של המסמך ללוח
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>.
vue
העתקת קוד
העתקת הקוד ללוח
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.
