Skip to content

Commit 465656f

Browse files
committed
fix: add styled 404 page to docs website
- Replaced auto-redirect with styled 404 page - Added bunny illustration from blog-website - Implemented 'Back to Home' and 'Go to Previous Page' buttons - Two-column responsive layout (desktop: side-by-side, mobile: stacked) - Full dark/light mode support - Accessibility features and helpful links Fixes keploy/keploy#3441 Signed-off-by: Dhruv Goyal <[email protected]>
1 parent 6c8a433 commit 465656f

File tree

3 files changed

+122
-9
lines changed

3 files changed

+122
-9
lines changed
Lines changed: 122 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,126 @@
1-
import {useEffect} from "react";
1+
import React from 'react';
2+
import { useHistory } from '@docusaurus/router';
3+
import { translate } from '@docusaurus/Translate';
4+
import { Home, ArrowLeft } from 'lucide-react';
25

3-
export default function NotFound() {
4-
useEffect(() => {
5-
if (typeof window !== "undefined") {
6-
// immediate redirect without adding to browser history
7-
window.location.replace("/docs");
6+
/**
7+
* Custom 404 Page Component for Keploy Docs
8+
*
9+
* Issue #3441: Add styled 404 page to docs website
10+
* Requirements from @amaan-bhati:
11+
* - Styled 404 page (not auto-redirect)
12+
* - Docs navbar/header (already provided by Layout wrapper)
13+
* - "Back to Home" button to return to docs homepage
14+
* - "Go to Previous Page" button (if navigation history exists)
15+
* - Good illustration/image that says 404
16+
* - Should work with dark/light theme
17+
* - Responsive design for mobile and desktop
18+
*/
19+
export default function NotFoundContent() {
20+
const history = useHistory();
21+
22+
// Handle "Go to Previous Page" button click
23+
const handleGoBack = () => {
24+
// Check if there's previous page in history
25+
if (window.history.length > 1) {
26+
history.goBack();
27+
} else {
28+
// If no history, go to home
29+
history.push('/docs/');
830
}
9-
}, []);
31+
};
32+
33+
return (
34+
<div className="flex min-h-[calc(100vh-var(--ifm-navbar-height))] items-center justify-center px-4 py-16">
35+
{/* Two-column layout: Text on left, Image on right */}
36+
<div className="flex max-w-6xl flex-col-reverse items-center gap-12 lg:flex-row lg:gap-16">
37+
38+
{/* Left Column: Text Content and Buttons */}
39+
<div className="flex-1 text-center lg:text-left">
40+
{/* Error Message */}
41+
<h1 className="mb-4 text-6xl font-bold text-[color:var(--ifm-color-primary)]">
42+
Oops! 404
43+
</h1>
44+
45+
<h2 className="mb-4 text-3xl font-semibold text-[color:var(--ifm-color)]">
46+
{translate({
47+
id: 'theme.NotFound.title',
48+
message: 'Page Not Found',
49+
})}
50+
</h2>
51+
52+
<p className="mb-8 text-lg text-[color:var(--ifm-color-emphasis-600)]">
53+
{translate({
54+
id: 'theme.NotFound.p1',
55+
message: "We couldn't find what you're looking for. The page you are trying to access doesn't exist or has been moved.",
56+
})}
57+
</p>
58+
59+
{/* Action Buttons */}
60+
<div className="flex flex-col gap-4 sm:flex-row lg:justify-start">
61+
{/* Primary Button: Back to Home */}
62+
<a
63+
href="/docs/"
64+
className="inline-flex items-center justify-center gap-2 rounded-lg bg-[color:var(--ifm-color-primary)] px-6 py-3 font-semibold text-white shadow-lg transition-all hover:scale-105 hover:bg-[color:var(--ifm-color-primary-dark)] hover:no-underline hover:text-white focus:outline-none focus:ring-2 focus:ring-[color:var(--ifm-color-primary)] focus:ring-offset-2"
65+
aria-label="Go back to documentation homepage"
66+
>
67+
<Home size={20} aria-hidden="true" />
68+
Back to Home
69+
</a>
70+
71+
{/* Secondary Button: Go to Previous Page */}
72+
<button
73+
onClick={handleGoBack}
74+
className="inline-flex items-center justify-center gap-2 rounded-lg border-2 border-[color:var(--ifm-color-primary)] bg-transparent px-6 py-3 font-semibold text-[color:var(--ifm-color-primary)] shadow-sm transition-all hover:scale-105 hover:bg-[color:var(--ifm-color-primary)] hover:text-white focus:outline-none focus:ring-2 focus:ring-[color:var(--ifm-color-primary)] focus:ring-offset-2"
75+
aria-label="Navigate to previous page"
76+
>
77+
<ArrowLeft size={20} aria-hidden="true" />
78+
Go to Previous Page
79+
</button>
80+
</div>
81+
82+
{/* Helpful Links */}
83+
<div className="mt-12 border-t border-[color:var(--ifm-color-emphasis-300)] pt-8">
84+
<p className="mb-4 text-sm font-semibold uppercase tracking-wide text-[color:var(--ifm-color-emphasis-600)]">
85+
Helpful Links
86+
</p>
87+
<div className="flex flex-wrap justify-center gap-4 text-sm lg:justify-start">
88+
<a
89+
href="/docs/server/installation"
90+
className="text-[color:var(--ifm-color-primary)] hover:underline"
91+
>
92+
Installation Guide
93+
</a>
94+
<span className="text-[color:var(--ifm-color-emphasis-400)]"></span>
95+
<a
96+
href="/docs/concepts/reference/glossary/"
97+
className="text-[color:var(--ifm-color-primary)] hover:underline"
98+
>
99+
Glossary
100+
</a>
101+
<span className="text-[color:var(--ifm-color-emphasis-400)]"></span>
102+
<a
103+
href="https://github.com/keploy/keploy"
104+
className="text-[color:var(--ifm-color-primary)] hover:underline"
105+
target="_blank"
106+
rel="noopener noreferrer"
107+
>
108+
GitHub Repository
109+
</a>
110+
</div>
111+
</div>
112+
</div>
113+
114+
{/* Right Column: 404 Illustration */}
115+
<div className="flex-1 flex items-center justify-center">
116+
<img
117+
src="/docs/img/404-not-found.png"
118+
alt="404 - Page not found illustration"
119+
className="h-auto w-full max-w-md object-contain"
120+
/>
121+
</div>
10122

11-
// render nothing (no content shown)
12-
return null;
123+
</div>
124+
</div>
125+
);
13126
}

static/img/404-not-found.png

328 KB
Loading

static/img/error-404.png

215 KB
Loading

0 commit comments

Comments
 (0)