nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.76k stars 485 forks source link

Allow using `app/router.options.ts` or routes options for routing #1836

Open huang-julien opened 1 year ago

huang-julien commented 1 year ago

Describe the feature

Hi :wave:

Currently the module only generate routes with the page directory. Is it possible to add a routes or router option to generate localized routes instead of using the page directory ?

Additional information

Final checks

ineshbose commented 1 year ago

Related: #1676

ponjs commented 1 month ago
// router.options.ts
import type { RouterConfig } from '@nuxt/schema'
import { localizeRoutes, type I18nRoutingOptions } from 'vue-i18n-routing'
import type { RouteRecordRaw } from 'vue-router'
import { nuxtI18nOptions } from '#build/i18n.options.mjs'

export default {
  routes: _routes =>
    localizeRoutes(
      [
        {
          name: 'Home',
          path: '/',
          component: () => import('@/pages/home/page.vue'),
        },
        {
          name: 'About',
          path: '/about',
          component: () => import('@/pages/about/page.vue'),
        },
      ],
      nuxtI18nOptions satisfies I18nRoutingOptions
    ) as RouteRecordRaw[],
} satisfies RouterConfig