From edb580efefb566567bb9d64c2814dcd36067cc46 Mon Sep 17 00:00:00 2001 From: Gage Krumbach Date: Tue, 15 Oct 2024 16:01:45 -0500 Subject: [PATCH] fix redirect in docs --- gatsby-node.ts | 2 +- src/pages/404.tsx | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gatsby-node.ts b/gatsby-node.ts index 1ca008d4042..c9e8f125345 100644 --- a/gatsby-node.ts +++ b/gatsby-node.ts @@ -168,7 +168,7 @@ export const createPages: GatsbyNode["createPages"] = async ({ const { createPage, createRedirect } = actions; createRedirect({ - fromPath: "/docs/", + fromPath: "/docs", isPermanent: false, redirectInBrowser: true, toPath: "/docs/getting-started-with-open-data-hub", diff --git a/src/pages/404.tsx b/src/pages/404.tsx index a71787c9fe4..16561a6eebc 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,17 +1,17 @@ -import { HeadFC, Link, PageProps } from "gatsby"; -import * as React from "react"; +import React, { useEffect } from "react" +import { navigate } from "gatsby" -const NotFoundPage: React.FC = () => { - return ( -
-

Page not found

-

- Go home -

-
- ); -}; +const NotFoundPage = () => { + useEffect(() => { + const path = window.location.pathname + if (path === "/docs" || path === "/docs/") { + navigate("/docs/getting-started-with-open-data-hub") + } else { + navigate("/") // or to any default 404 page + } + }, []) -export default NotFoundPage; + return
Redirecting...
+} -export const Head: HeadFC = () => Not found; +export default NotFoundPage