_error.page.tsx 665 B

123456789101112131415161718
  1. import type { NextPageContext } from 'next';
  2. import type { ErrorProps } from 'next/error';
  3. import Error from 'next/error';
  4. export default function ErrorPage(props: ErrorProps): JSX.Element {
  5. return <Error {...props} />;
  6. }
  7. // add getInitialProps to disable "https://nextjs.org/docs/messages/prerender-error"
  8. // Error: Export encountered errors on following paths:
  9. // /_error: /404
  10. // /_error: /500
  11. // see: https://github.com/vercel/next.js/issues/23568#issuecomment-814971318
  12. ErrorPage.getInitialProps = (ctx: NextPageContext) => {
  13. const { res, err } = ctx;
  14. const statusCode = res?.statusCode ?? err?.statusCode ?? 500;
  15. return { statusCode };
  16. };