Skip to content

Commit

Permalink
Add a simple default 404 page (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu authored Feb 18, 2025
2 parents 24dde0e + 1456106 commit 060b390
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions frontend/src/components/NotFound/NotFound.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { NotFound } from './NotFound';

describe('NotFound Component', () => {
it('should render a 404 text', () => {
render(<NotFound />);
expect(screen.getByText('Oops, page not found')).toBeInTheDocument();
});
});
18 changes: 18 additions & 0 deletions frontend/src/components/NotFound/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Link } from '@tanstack/react-router';
import { FC } from 'react';

export const NotFound: FC = () => {
return (
<div className="h-screen w-screen flex items-center justify-center">
<div className="space-y-4">
<h1 className="text-2xl">Oops, page not found</h1>
<Link
to="/"
className="px-6 py-3 block text-center bg-gray-700 text-white hover:bg-gray-800 focus:ring-gray-500 rounded-lg"
>
Go Back Home
</Link>
</div>
</div>
);
};
2 changes: 2 additions & 0 deletions frontend/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ export type { CommentBubbleProps } from './CommentBubble';

export { FileDownload } from './FileDownload';
export type { FileDownloadProps } from './FileDownload';

export { NotFound } from './NotFound/NotFound';
6 changes: 4 additions & 2 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { routeTree } from './routeTree.gen';

import './index.css';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { NotFound } from '@components';

const queryClient = new QueryClient();

function Router() {
const auth = useAuth();

if (auth.isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
Expand All @@ -30,8 +31,9 @@ function Router() {
context: {
auth,
},
defaultNotFoundComponent: NotFound,
});

return <RouterProvider router={router} context={{ auth }} />;
}

Expand Down

0 comments on commit 060b390

Please sign in to comment.