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

Commit a8bf845

Browse files
committed
update withoutProps/redirects to accommodate defaultLocale
1 parent 2b7c6e0 commit a8bf845

File tree

3 files changed

+312
-3138
lines changed

3 files changed

+312
-3138
lines changed

lib/pages/withoutProps/redirects.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
const isDynamicRoute = require("../../helpers/isDynamicRoute");
22
const pages = require("./pages");
3+
const getNextConfig = require("../../helpers/getNextConfig");
34

45
const redirects = [];
56

7+
const nextConfig = getNextConfig();
8+
69
pages.forEach(({ route, filePath }) => {
10+
// If i18n, need to accommodate for defaultLocale
11+
if (nextConfig.i18n) {
12+
const { defaultLocale } = nextConfig.i18n;
13+
// For example, '/en/some/path -> 'en'
14+
const routeLocale = route.split("/")[1];
15+
if (routeLocale === defaultLocale) {
16+
const defaultLocaleRoute =
17+
route === `/${routeLocale}`
18+
? "/"
19+
: route.replace(`/${routeLocale}`, "");
20+
redirects.push({
21+
route: defaultLocaleRoute,
22+
target: filePath.replace(/pages/, ""),
23+
});
24+
}
25+
}
26+
727
// Only create redirects for pages with dynamic routing
828
if (!isDynamicRoute(route)) return;
929

0 commit comments

Comments
 (0)