vue-i18n-routing is a critical extension within the Intlify ecosystem, designed to seamlessly integrate internationalization capabilities (provided by `vue-i18n`) with client-side routing (provided by `vue-router`). It enhances `vue-router` by enabling locale-aware URL patterns, dynamic route parameter handling for locales, and helper functions for navigating between localized routes. The package is currently at version 1.2.0 and receives active maintenance, evidenced by recent bug fixes and feature additions. Its primary differentiator is providing a cohesive solution for managing multi-language URLs without boilerplate, supporting both Vue 2 (via `vue-i18n-bridge` and `@vue/composition-api`) and Vue 3 environments. It abstracts the complexity of locale prefixes and path resolution, making it easier to build SEO-friendly, internationalized Vue applications with consistent user experiences across different languages.
npm install vue-i18n-routingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic Vue 3 application with `vue-i18n` and `vue-i18n-routing`. It configures two locales (English and French), defines locale-prefixed routes, and shows how to use `useLocalePath` for navigation and `useSwitchLocalePath` to dynamically change the current route's locale. This setup is typical for creating internationalized Single Page Applications (SPAs) where the locale is managed via URL segments.
Carefully review the package's `peerDependencies` and install compatible versions. For Vue 2 projects needing Vue 3 Composition API features, ensure `@vue/composition-api` and `vue-i18n-bridge` are installed and correctly configured.
Upgrade to `vue-i18n-routing` version 1.1.4 or higher to benefit from fixes related to URL encoding and query parameter preservation when switching locales. Always test locale switching thoroughly after updates.
Always import `createRouter` from `'vue-i18n-routing'` when setting up your router to ensure i18n functionalities are correctly integrated. Pass the `vue-router` instance and `vue-i18n` instance to it.
Ensure `legacy: false` is explicitly set when initializing `createI18n` for modern Vue 3 Composition API usage: `createI18n({ ..., legacy: false })`.Ensure you call `app.use(i18n)` and `app.use(router)` (where `router` is the instance created by `vue-i18n-routing`) before `app.mount('#app')`.Verify that `createI18n` is called correctly and its instance is passed to `app.use()`. Also, ensure that any components using i18n hooks or global properties are within the `app`'s scope after `app.use(i18n)` has been called.
Confirm that your `vue-router` routes are correctly defined with a dynamic `:locale` segment at the root. For example, `{ path: '/:locale', children: [...] }`. Also, ensure the route name is consistent if using named routes with `localePath`.