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

Commit e1cda1a

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

File tree

3 files changed

+309
-3138
lines changed

3 files changed

+309
-3138
lines changed

lib/pages/withoutProps/redirects.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
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+
const defaultLocaleRoute =
16+
route === `/${routeLocale}` ? "/" : route.replace(`/${routeLocale}`, "");
17+
redirects.push({
18+
route: defaultLocaleRoute,
19+
target: filePath.replace(/pages/, ""),
20+
});
21+
return;
22+
}
23+
724
// Only create redirects for pages with dynamic routing
825
if (!isDynamicRoute(route)) return;
926

0 commit comments

Comments
 (0)