diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index e001461593e2..ba8a0fd2174f 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -591,8 +591,20 @@ export class RenderContext { computedLocale = computeCurrentLocale(referer, locales, defaultLocale); } } else { - const pathname = - routeData.pathname && !isRoute404or500(routeData) ? routeData.pathname : url.pathname; + // For SSG we match the route naively, for dev we handle fallback on 404, for SSR we find route from fallbackRoutes + const route = + (routeData.pattern.test(url.pathname) + ? routeData + : routeData.fallbackRoutes.find((fallbackRoute) => + fallbackRoute.pattern.test(url.pathname), + )) ?? routeData; + const pathname = route.pathname && !isRoute404or500(route) ? route.pathname : url.pathname; + // console.log('route', route); + // console.table({ + // routePath: routeData.pathname, + // is404Or500: isRoute404or500(routeData), + // urlPathname: url.pathname, + // }); computedLocale = computeCurrentLocale(pathname, locales, defaultLocale); } diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index dc338c7db0b7..9d98a8cf0016 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,6 +1,6 @@ +import * as cheerio from 'cheerio'; import * as assert from 'node:assert/strict'; import { after, afterEach, before, describe, it } from 'node:test'; -import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js';