i18n
Nuxt typed router has out of the box support for @nuxtjs/i18n
To try it
yarn
yarn add @nuxtjs/i18n@next
nuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-typed-router',
'@nuxtjs/i18n'
],
i18n: // your i18n config
})
You will have autocomplete for
- Only the default routes when using
prefix(*)
strategies. - The registered locales
useLocalePath()
Global types for useLocalePath
will be overwritten, and the function is also exported from @typed-router
.
const localePath = useLocalePath();
navigateTo(localePath({ name: 'user-id'}, 'fr')); // Error ❌
navigateTo(localePath({ name: 'user-id', params: {id: 1}}, 'fr')); // Good ✅
useLocaleRoute()
Global types for useLocaleRoute
will be overwritten, and the function is also exported from @typed-router
.
const localeRoute = useLocaleRoute();
const route = localeRoute({ name: 'user-id', }, 'fr'); // Error ❌
const route = localeRoute({ name: 'user-id', params: {id: 1} } , 'fr'); // Good ✅
if (route) {
navigateTo(route.fullPath);
}
Table of Contents