Skip to content

Commit

Permalink
feat: react router error handling for 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian4res committed Jun 30, 2024
1 parent 12606f9 commit 0f5a0b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -56,6 +57,9 @@ function App(): ReactElement {
<Home />
</ErrorBoundary>
}/>
<Route path="*" element={
<PageNotFound />
}/>
</Routes>
</DefaultErrorBoundary>
</div>
Expand Down
18 changes: 18 additions & 0 deletions src/Components/PageNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

export default function PageNotFound() {
return (<>
<div className="ons-page__container ons-container">
<div className="ons-grid">
<div className="ons-grid__col ons-col-12@m ">
<main id="main-content" className="ons-page__main ">
<h1>Page not found</h1>
<p>If you entered a web address, check it is correct.</p>
<p>If you pasted the web address, check you copied the whole address.</p>
<p>If the web address is correct, or you selected a link or button, <a href="#0">contact us</a>.</p>
</main>
</div>
</div>
</div>
</>);
}

0 comments on commit 0f5a0b8

Please sign in to comment.