Skip to content

Commit 0d1315c

Browse files
committed
feat(module): add internal path check for route generation
1 parent 32f275c commit 0d1315c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/module.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import {
1919
isNoPrefixStrategy,
2020
isPrefixStrategy,
2121
withPrefixStrategy,
22-
isPrefixExceptDefaultStrategy, isPrefixAndDefaultStrategy,
22+
isPrefixExceptDefaultStrategy,
23+
isPrefixAndDefaultStrategy,
2324
} from 'nuxt-i18n-micro-core'
2425
import { setupDevToolsUI } from './devtools'
2526
import { PageManager } from './page-manager'
2627
import type { PluginsInjections } from './runtime/plugins/01.plugin'
2728
import { LocaleManager } from './locale-manager'
2829

30+
const isInternalPath = (p: string) => /(?:^|\/)__[^/]+/.test(p)
31+
2932
function generateI18nTypes() {
3033
return `
3134
import type {PluginsInjections} from "nuxt-i18n-micro";
@@ -410,7 +413,8 @@ export default defineNuxtModule<ModuleOptions>({
410413
const shouldGenerate = locale.code !== defaultLocale || withPrefixStrategy(options.strategy!)
411414
if (shouldGenerate) {
412415
pages.forEach((page) => {
413-
if (!/\.[a-z0-9]+$/i.test(page)) {
416+
// Пропускаем файлоподобные пути и служебные сегменты `__*`
417+
if (!/\.[a-z0-9]+$/i.test(page) && !isInternalPath(page)) {
414418
routes.push(`/${locale.code}${page}`)
415419
}
416420
})
@@ -466,10 +470,9 @@ export default defineNuxtModule<ModuleOptions>({
466470
}
467471
const routesSet = prerenderRoutes.routes
468472
const additionalRoutes = new Set<string>()
469-
470473
// Проходим по каждому существующему маршруту и добавляем локализованные версии
471474
routesSet.forEach((route) => {
472-
if (!/\.[a-z0-9]+$/i.test(route)) {
475+
if (!/\.[a-z0-9]+$/i.test(route) && !isInternalPath(route)) {
473476
localeManager.locales!.forEach((locale) => {
474477
// Для стратегий prefix и prefix_and_default генерируем маршруты и для defaultLocale
475478
// Для стратегии prefix_except_default пропускаем defaultLocale

0 commit comments

Comments
 (0)