Skip to content

Commit 093fc69

Browse files
authored
Merge pull request #7137 from ethereum/resolve-404-pages
Resolve 404 pages
2 parents 47df8a4 + 02267b3 commit 093fc69

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

gatsby-browser.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
defaultLanguage,
2323
isLang,
2424
} from "./src/utils/languages"
25+
import { IS_DEV } from "./src/utils/env"
2526
import { Context } from "./src/types"
2627

2728
// Default languages included:
@@ -42,7 +43,7 @@ export const wrapPageElement: GatsbyBrowser<
4243

4344
// client side redirect on paths that don't have a locale in them. Most useful
4445
// on dev env where we don't have server redirects
45-
if (!isLang(pathLocale)) {
46+
if (IS_DEV && !isLang(pathLocale)) {
4647
let detected =
4748
window.localStorage.getItem("eth-org-language") ||
4849
browserLang({

gatsby-config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,19 @@ const config: GatsbyConfig = {
230230
},
231231
},
232232
// Needed for Gatsby Cloud redirect support
233-
`gatsby-plugin-gatsby-cloud`,
233+
{
234+
resolve: `gatsby-plugin-gatsby-cloud`,
235+
options: {
236+
generateMatchPathRewrites: false,
237+
},
238+
},
234239
// Creates `_redirects` & `_headers` build files for Netlify
235-
`gatsby-plugin-netlify`,
240+
{
241+
resolve: `gatsby-plugin-netlify`,
242+
options: {
243+
generateMatchPathRewrites: false,
244+
},
245+
},
236246
],
237247
// https://www.gatsbyjs.com/docs/reference/release-notes/v2.28/#feature-flags-in-gatsby-configjs
238248
flags: {

gatsby-node.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ export const onCreatePage: GatsbyNode<any, Context>["onCreatePage"] = async ({
420420
}
421421
}
422422

423+
export const onPostBootstrap: GatsbyNode["onPostBootstrap"] = ({ actions }) => {
424+
const { createRedirect } = actions
425+
426+
supportedLanguages.forEach((lang) => {
427+
createRedirect({
428+
...commonRedirectProps,
429+
fromPath: `/${lang}/*`,
430+
toPath: `/${lang}/404`,
431+
statusCode: 404,
432+
force: false,
433+
})
434+
})
435+
}
436+
423437
export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] =
424438
({ actions, schema }) => {
425439
const { createTypes } = actions

redirects.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
"fromPath": "/build/",
5656
"toPath": "/en/developers/learning-tools/"
5757
},
58-
{
59-
"fromPath": "/enterprise/",
60-
"toPath": "/en/enterprise/"
61-
},
6258
{
6359
"fromPath": "/java/",
6460
"toPath": "/en/developers/docs/programming-languages/java/"
@@ -92,13 +88,21 @@
9288
"toPath": "/en/developers/docs/programming-languages/dart/"
9389
},
9490
{
95-
"fromPath": "/nft/",
91+
"fromPath": "/nfts/",
9692
"toPath": "/en/nft/"
9793
},
9894
{
9995
"fromPath": "/daos/",
10096
"toPath": "/en/dao/"
10197
},
98+
{
99+
"fromPath": "/layer2/",
100+
"toPath": "/en/layer-2/"
101+
},
102+
{
103+
"fromPath": "/*/layer2/",
104+
"toPath": "/:splat/layer-2/"
105+
},
102106
{
103107
"fromPath": "/grants/",
104108
"toPath": "/en/community/grants/"

0 commit comments

Comments
 (0)