From 482ea8d8849ee20b9c21d9911c8bdc9a801a4efa Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Thu, 11 Jul 2019 21:37:35 +0200 Subject: [PATCH] fix(gatsby): handle `/404/`, `/404`, `404/` or `404` page paths (#15615) --- docs/docs/add-404-page.md | 2 +- packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/add-404-page.md b/docs/docs/add-404-page.md index 4bee550e0fdc3..6dbff94ecdf3c 100644 --- a/docs/docs/add-404-page.md +++ b/docs/docs/add-404-page.md @@ -3,7 +3,7 @@ title: "Adding a 404 Page" --- To create a 404 page create a page whose path matches the regex -`/404*`. Most often you'll want to create a React component page at +`^\/?404\/?$` (`/404/`, `/404`, `404/` or `404`). Most often you'll want to create a React component page at `src/pages/404.js`. Gatsby ensures that your 404 page is built as `404.html` as many static hosting diff --git a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js index e74f4f0babdac..d1ff7d6694339 100644 --- a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js @@ -3,7 +3,7 @@ exports.onCreatePage = ({ page, store, actions }) => { // Copy /404/ to /404.html as many static site hosts expect // site 404 pages to be named this. // https://www.gatsbyjs.org/docs/add-404-page/ - if (!created404 && page.path === `/404/`) { + if (!created404 && /^\/?404\/?$/.test(page.path)) { actions.createPage({ ...page, path: `/404.html`,