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

Commit 60e8a49

Browse files
committed
root level index pages need special dataRoute logic
1 parent 04d57b4 commit 60e8a49

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lib/pages/getServerSideProps/redirects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ pages.forEach(({ route, filePath }) => {
3030
target,
3131
});
3232
redirects.push({
33-
route: getDataRouteForRoute(route, locale),
33+
route:
34+
route === "/"
35+
? getDataRouteForRoute(`/${locale}`)
36+
: getDataRouteForRoute(route, locale),
3437
target,
3538
});
3639
});

lib/pages/getStaticProps/setup.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ const setup = ({ functionsPath, publishPath }) => {
4040
const htmlPath = getFilePathForRoute(route_, "html", locale);
4141
setupStaticFileForPage({ inputPath: htmlPath, publishPath });
4242

43-
const jsonPath = getFilePathForRoute(route_, "json", locale);
4443
// The provided dataRoutes (from prerender-manifest) for these page types
4544
// actually don't include the locale (unclear why Vercel did this)
4645
// BUT the actual path to the .json files DO include the locale
4746
// therefore we need to set up the .json pages in the locale loop and
4847
// ignore the dataRoute provided by the prerender-manifest
49-
const i18nDataRoute = getDataRouteForRoute(route, locale);
48+
// Also root-level pages are generated into dist at path -> /en/index.json
49+
// but fetched on the client as /_next/data/{BUILD_ID}/en.json haha love that for me
50+
const jsonPath =
51+
route === "/"
52+
? getFilePathForRoute(`/${locale}`, "json")
53+
: getFilePathForRoute(route_, "json", locale);
54+
const i18nDataRoute =
55+
route === "/"
56+
? getDataRouteForRoute(`/${locale}`)
57+
: getDataRouteForRoute(route, locale);
5058
setupStaticFileForPage({
5159
inputPath: jsonPath,
5260
outputPath: i18nDataRoute,

lib/pages/getStaticPropsWithRevalidate/redirects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pages.forEach(({ route, srcRoute, dataRoute }) => {
5252
});
5353
// Add a redirect for each dataRoute per locale
5454
redirects.push({
55-
route: getDataRouteForRoute(route, locale),
55+
route:
56+
route === "/"
57+
? getDataRouteForRoute(`/${locale}`)
58+
: getDataRouteForRoute(route, locale),
5659
target,
5760
});
5861
});

0 commit comments

Comments
 (0)