Skip to content

Commit 26b930a

Browse files
fix:404-redirection-fix
Signed-off-by: Iam-karan-suresh <[email protected]>
1 parent 3108d29 commit 26b930a

File tree

2 files changed

+103
-18
lines changed

2 files changed

+103
-18
lines changed

src/components/NotFoundPage.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import error from "../../static/img/error404.png";
2+
import error from "/static/img/error404.png";
33

44
const NotFoundPage = () => {
55
return (
@@ -17,7 +17,9 @@ const NotFoundPage = () => {
1717
style={{margin: "0 auto"}}
1818
/>
1919
<h1 className="hero__title">🐰 Oops! 🐰</h1>
20-
<p className="hero__subtitle margin-vert--md">404 - Page Not Found</p>
20+
<p className="hero__subtitle margin-vert--md">
21+
404 - Page Not Found
22+
</p>
2123
<div className="margin-vert--lg">
2224
<div className="loading-dots">
2325
<span>Redirecting to documentation</span>

src/theme/NotFound/Content/index.js

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,110 @@
1-
import React from "react";
1+
import React, {useEffect, useState} from "react";
22
import {translate} from "@docusaurus/Translate";
33
import Link from "@docusaurus/Link";
44
import {PageMetadata} from "@docusaurus/theme-common";
5+
import useBaseUrl from "@docusaurus/useBaseUrl";
56

67
export default function NotFound() {
8+
const [requestedUrl, setRequestedUrl] = useState("");
9+
10+
useEffect(() => {
11+
// capture the full URL client-side and trigger a redirect after 2s
12+
if (typeof window !== "undefined") {
13+
setRequestedUrl(window.location.href);
14+
const id = setTimeout(() => {
15+
window.location.href = "/docs/";
16+
}, 2000);
17+
return () => clearTimeout(id);
18+
}
19+
return undefined;
20+
}, []);
21+
722
return (
823
<>
924
<PageMetadata title="Page Not Found" />
10-
<main className="container margin-vert--xl">
11-
<div className="row">
12-
<div className="col col--6 col--offset-3 text-center">
13-
<h1 className="hero__title">404: Page Not Found</h1>
14-
<p className="padding-vert--md">
15-
We could not find what you were looking for.<br />
16-
The page you requested may have been moved or deleted.
17-
</p>
18-
<div className="margin-vert--lg">
19-
<Link to="/docs/" className="button button--primary margin-right--md">
20-
Back to Homepage
21-
</Link>
22-
<Link to="/docs/search" className="button button--secondary">
23-
Search Documentation
24-
</Link>
25+
<main
26+
style={{
27+
height: "100vh",
28+
display: "flex",
29+
alignItems: "center",
30+
justifyContent: "center",
31+
overflow: "hidden",
32+
padding: "20px 0",
33+
}}
34+
>
35+
<div className="container">
36+
<div className="row">
37+
<div className="col col--6 col--offset-3 text-center">
38+
<div
39+
style={{
40+
maxHeight: "100vh",
41+
display: "flex",
42+
flexDirection: "column",
43+
gap: "1rem",
44+
}}
45+
>
46+
<img
47+
src={require("@site/static/img/error404.png").default}
48+
alt={translate({message: "404 - Page Not Found"})}
49+
style={{
50+
width: "380px",
51+
maxWidth: "100%",
52+
height: "auto",
53+
display: "block",
54+
margin: "0 auto",
55+
}}
56+
/>
57+
58+
<h1
59+
className="hero__title"
60+
style={{
61+
color: "var(--ifm-color-primary)",
62+
margin: "0.5rem 0",
63+
fontSize: "2rem",
64+
}}
65+
>
66+
404: Page Not Found
67+
</h1>
68+
69+
<p
70+
style={{
71+
color: "var(--ifm-color-emphasis-700)",
72+
margin: "0.5rem 0",
73+
}}
74+
>
75+
We could not find what you were looking for.
76+
<br />
77+
The page you requested may have been moved or deleted.
78+
</p>
79+
80+
{requestedUrl && (
81+
<p
82+
style={{
83+
color: "var(--ifm-color-emphasis-600)",
84+
margin: "0.25rem 0",
85+
fontSize: "0.9rem",
86+
}}
87+
>
88+
Requested URL: <code>{requestedUrl}</code>
89+
</p>
90+
)}
91+
92+
<p
93+
style={{
94+
color: "var(--ifm-color-primary)",
95+
margin: "0.25rem 0",
96+
fontSize: "0.9rem",
97+
}}
98+
>
99+
Redirecting to documentation...
100+
</p>
101+
102+
<div style={{marginTop: "0.5rem"}}>
103+
<Link to="/docs/" className="button button--primary">
104+
Go to Documentation
105+
</Link>
106+
</div>
107+
</div>
25108
</div>
26109
</div>
27110
</div>

0 commit comments

Comments
 (0)