Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit acc13c9

Browse files
committed
fix/move fallback i18n logic
1 parent 90856ad commit acc13c9

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/pages/getStaticProps/pages.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ const getPrerenderManifest = require("../../helpers/getPrerenderManifest");
44
const pages = [];
55

66
// Get pages using getStaticProps
7-
const { routes, dynamicRoutes } = getPrerenderManifest();
8-
9-
const isFallbackRoute = (srcRoute) => {
10-
return dynamicRoutes[srcRoute] && !!dynamicRoutes[srcRoute].fallback;
11-
};
7+
const { routes } = getPrerenderManifest();
128

139
// Parse static pages
1410
Object.entries(routes).forEach(
1511
([route, { dataRoute, initialRevalidateSeconds, srcRoute }]) => {
1612
// Ignore pages with revalidate, these will need to be SSRed
1713
if (initialRevalidateSeconds) return;
18-
// Exclude routes with fallback, this is handled in getStaticPropsWithFallback
19-
if (isFallbackRoute(srcRoute)) return;
2014

2115
pages.push({
2216
route,

lib/pages/getStaticProps/redirects.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const getFilePathForRoute = require("../../helpers/getFilePathForRoute");
33
const getDataRouteForRoute = require("../../helpers/getDataRouteForRoute");
44
const getNetlifyFunctionName = require("../../helpers/getNetlifyFunctionName");
55
const nextConfig = require("../../helpers/getNextConfig")();
6+
const getPrerenderManifest = require("../../helpers/getPrerenderManifest");
67
const pages = require("./pages");
78

89
// Pages with getStaticProps (without fallback or revalidation) only need
@@ -27,6 +28,11 @@ const redirects = [];
2728
const dynamicDefaultLocaleRedirectsAdded = [];
2829
const dynamicLocaleSrcRoutesAdded = [];
2930

31+
const { dynamicRoutes } = getPrerenderManifest();
32+
const isFallbackRoute = (srcRoute) => {
33+
return dynamicRoutes[srcRoute] && !!dynamicRoutes[srcRoute].fallback;
34+
};
35+
3036
pages.forEach(({ route, dataRoute, srcRoute }) => {
3137
const relativePath = getFilePathForRoute(srcRoute || route, "js");
3238
const filePath = join("pages", relativePath);
@@ -69,9 +75,12 @@ pages.forEach(({ route, dataRoute, srcRoute }) => {
6975
// i.e. /getStaticProps/23 -> /en/getStaticProps/23
7076
// BUT we only have to do this *once* per srcRoute (within this pages loop)
7177
// so we track the srcRoutes we've already added redirects for
78+
// Also skip fallback srcRoutes, not needed because getStaticPropsWithFallback
79+
// logic will add this redirect
7280
if (
7381
defaultLocale &&
74-
!dynamicDefaultLocaleRedirectsAdded.includes(srcRoute)
82+
!dynamicDefaultLocaleRedirectsAdded.includes(srcRoute) &&
83+
!isFallbackRoute(srcRoute)
7584
) {
7685
const formattedSrcRoute = srcRoute.replace("[", ":").replace("]", "");
7786
const defaultLocaleTarget = `/${defaultLocale}${formattedSrcRoute}`;

0 commit comments

Comments
 (0)