Skip to content

Commit

Permalink
find fallback route for astro.currentLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwilliams-code committed Dec 27, 2024
1 parent da060ba commit ab17c34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit ab17c34

Please sign in to comment.