-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_error.tsx
42 lines (37 loc) · 1.11 KB
/
_error.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Link from 'next/link';
import { NextPageContext } from 'next';
interface ErrorProps {
statusCode?: number;
}
function Error({ statusCode }: ErrorProps) {
const message =
statusCode === 404
? 'Page not found'
: statusCode
? `An error ${statusCode} occurred on the server`
: 'An error occurred on the client';
return (
<div style={{ textAlign: 'center', padding: '50px' }}>
<h1 style={{ fontSize: '2em', marginBottom: '20px' }}>{statusCode ? `Error ${statusCode}` : 'Error'}</h1>
<p style={{ fontSize: '1.2em', color: '#555' }}>{message}</p>
{statusCode === 404 && (
<>
<p style={{ marginTop: '20px' }}>
Perhaps you were looking for:
</p>
<Link
href="/"
style={{ color: 'blue', textDecoration: 'none' }}
>
Go back to the homepage
</Link>
</>
)}
</div>
);
}
Error.getInitialProps = ({ res, err }: NextPageContext) => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};
export default Error;