custom-routes
app/router.options.ts
import type { RouterConfig } from "nuxt/schema";import routes_i18n from "../config/routes";const customRoutes = { miau: { route: routes_i18n.miau, component: () => import("~/pages/custom-component-page.vue"), },};export default { routes: (_routes) => { const routes = [..._routes]; // <<< because _routes is readonly Object.entries(customRoutes).forEach( ([routeName, { route, component }]) => { Object.entries(route).forEach(([lang, path]) => { routes.push({ path: `/${lang}${path}`, name: `${routeName}___${lang}`, component, }); }); } ); return routes; }} satisfies RouterConfig;
//nuxt.config.tsexport default defineNuxtConfig({ modules: [ CustomRoutesModule, '@nuxtjs/i18n', ], i18n: { // lazy: true, defaultLocale: 'en', strategy: 'prefix', customRoutes: 'config', pages: { about: {// <<<<<< this works en: "/about-us", it: "/chi-siamo", }, miau: {//<<<< this doesn't en: "/miau-translated", it: "/miau-translated-in-it", }, },})
// custom-routes.tsimport { defineNuxtModule, createResolver } from "@nuxt/kit";export default defineNuxtModule({ setup(options, nuxt) { const { resolve } = createResolver(import.meta.url); nuxt.hook("pages:extend", (pages) => { pages.push({ name: "miau", path: "/miau", file: resolve("../app/pages/custom-component-page.vue"), }); }); },});