[pages/404.jsx]
export default function Custom404() {
return <h1>404 - Page Not Found</h1>
}
[pages/_error.jsx]
const Error = ( {statusCode} ) => {
return (
<p>
{statusCode ? `An error ${statusCode} occurred on server` : 'An error occurred on client'}
</p>
);
};
Error.getInitialProps = ({ res, err }) => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};
export default Error;
[pages/404.tsx]
export default function Custom404() {
return <h1>404 - Page Not Found</h1>
}
[pages/_error.tsx]
import { NextPageContext } from 'next';
import { ErrorProps } from 'next/error';
const Error = ({ statusCode }: ErrorProps) => {
return (
<p>
{statusCode ? `An error ${statusCode} occurred on server` : 'An error occurred on client'}
</p>
);
};
Error.getInitialProps = ({ res, err }: NextPageContext) => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};
export default Error;