import type { RouterConfig } from '@nuxt/schema' import type { RouteRecordRaw } from 'vue-router' function shouldDuplicateRoute(path: string): boolean { if (path.startsWith('/admin')) return false if (path.startsWith('/zh')) return false if (path.includes('pathMatch')) return false return true } function duplicateRouteForZh(route: RouteRecordRaw): RouteRecordRaw { const zhPath = route.path === '/' ? '/zh' : `/zh${route.path}` return { ...route, path: zhPath, name: route.name ? `${String(route.name)}-zh` : undefined, children: route.children?.map(duplicateRouteForZh) } } export default { routes: (routes) => { const zhRoutes = routes .filter((route) => shouldDuplicateRoute(route.path)) .map(duplicateRouteForZh) return [...routes, ...zhRoutes] } } satisfies RouterConfig