From 0f5a0b8cef76e25ca53bd09e5a4aaf8f7a3eec64 Mon Sep 17 00:00:00 2001 From: kristian4res <57638182+kristian4res@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:14:34 +0100 Subject: [PATCH] feat: react router error handling for 404s --- server/server.ts | 1 + src/App.tsx | 4 ++++ src/Components/PageNotFound.tsx | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 src/Components/PageNotFound.tsx diff --git a/server/server.ts b/server/server.ts index 102a497..567aafe 100644 --- a/server/server.ts +++ b/server/server.ts @@ -59,6 +59,7 @@ export default function GetNodeServer(config: CustomConfig, blaiseApi: BlaiseApi if (!fs.existsSync(indexFilePath)) { indexFilePath = path.join(__dirname, "../public/index.html"); } + server.get("*", function (_req: Request, res: Response) { res.render(indexFilePath); }); diff --git a/src/App.tsx b/src/App.tsx index 9203ed1..9988f4f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,6 +12,7 @@ import { User } from "blaise-api-node-client"; import { Authenticate } from "blaise-login-react/blaise-login-react-client"; import UserProfile from "./pages/users/UserProfileEdits/UserProfile"; import ChangeRole from "./pages/users/UserProfileEdits/ChangeRole"; +import PageNotFound from "./Components/PageNotFound"; const divStyle = { minHeight: "calc(67vh)" @@ -56,6 +57,9 @@ function App(): ReactElement { }/> + + }/> diff --git a/src/Components/PageNotFound.tsx b/src/Components/PageNotFound.tsx new file mode 100644 index 0000000..b325904 --- /dev/null +++ b/src/Components/PageNotFound.tsx @@ -0,0 +1,18 @@ +import React from "react"; + +export default function PageNotFound() { + return (<> +
+
+
+
+

Page not found

+

If you entered a web address, check it is correct.

+

If you pasted the web address, check you copied the whole address.

+

If the web address is correct, or you selected a link or button, contact us.

+
+
+
+
+ ); +} \ No newline at end of file