-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Add smart fallback navigation to 404 page #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,20 @@ import { useNavigate } from 'react-router-dom'; | |
| export const NotFoundPage = () => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const handleGoBack = () => { | ||
| // Check if there's history to go back to (more than just current page) | ||
| if (window.history.length > 1) { | ||
| navigate(-1); | ||
| } else { | ||
| // No useful history, go to home | ||
| navigate('/'); | ||
|
Comment on lines
13
to
+20
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Navigate Handlers Lack useCallback Optimization
IssueThe handleGoBack and handleGoHome handlers are recreated on every render. While not causing issues here, using useCallback with proper dependencies is React best practice for event handlers, especially since other components in the codebase follow similar inline patterns without memoization. Suggested FixWrap handlers with useCallback: const handleGoBack = useCallback(() => { ... }, []); and const handleGoHome = useCallback(() => navigate('/'), [navigate]);. However, this is optional since the component is lightweight and these handlers are simple. |
||
| } | ||
| }; | ||
|
|
||
| const handleGoHome = () => { | ||
| navigate('/'); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className="landing relative flex min-h-screen items-center justify-center p-4" | ||
|
|
@@ -50,7 +64,7 @@ export const NotFoundPage = () => { | |
| <h1 className="landing-display mb-2 text-8xl font-black tracking-tighter text-[var(--metis-red)]"> | ||
| 404 | ||
| </h1> | ||
| <h2 className="landing-display text-2xl font-black">PAGE NOT FOUND</h2> | ||
| <h2 className="landing-display text-2xl font-black uppercase">Page Not Found</h2> | ||
| </div> | ||
|
|
||
| {/* Message */} | ||
|
|
@@ -61,26 +75,26 @@ export const NotFoundPage = () => { | |
| </div> | ||
|
|
||
| {/* Actions */} | ||
| <div className="flex gap-3"> | ||
| <div className="flex flex-col gap-3 sm:flex-row"> | ||
| <Button | ||
| onClick={() => navigate(-1)} | ||
| onClick={handleGoBack} | ||
| className="flex-1 border-2 border-black bg-white text-black shadow-[4px_4px_0px_0px_#000] transition-all hover:-translate-y-1 hover:shadow-[6px_6px_0px_0px_#000]" | ||
| size="lg" | ||
| > | ||
| <ArrowLeft className="mr-2 h-5 w-5" /> | ||
| Go Back | ||
| </Button> | ||
| <Button | ||
| onClick={() => navigate('/')} | ||
| onClick={handleGoHome} | ||
| className="flex-1 border-2 border-black bg-[var(--metis-orange)] text-white shadow-[4px_4px_0px_0px_#000] transition-all hover:-translate-y-1 hover:shadow-[6px_6px_0px_0px_#000]" | ||
| size="lg" | ||
| > | ||
| <Home className="mr-2 h-5 w-5" /> | ||
| Home | ||
| Go Home | ||
| </Button> | ||
| </div> | ||
| </CardContent> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| }; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Newline Missing in File
INFOSTYLEIssue
The file is missing a trailing newline at the end of the file, which is a common code style convention for text files and is often enforced by linters and git configurations.
Suggested Fix
Add a trailing newline at the end of the file after the closing brace.