Development/React.js

next - _error.js

moretz0921 2022. 4. 14. 23:23

_error : 전역에서 Error 처리를 공통으로 사용 

- Next에서 자체적으로 제공해주는 에러 태그는 서버와 클라이언트 모두에서 동작한다.
- 404에러(not found)와 500에러(서버 에러)를 제외한 이외의 에러들은 _error.js 라는 파일명으로 커스텀한다.

 
설정 

function 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

 

 

출처

https://jungyosup.github.io/next/next01/#51-nextjs-404-error-customizing

 

1.NEXT JS

NEXT JS에 관해서

jungyosup.github.io

 

https://intrepidgeeks.com/tutorial/nextjs-default-error-page

 

Next.js Default error page

https://nextjs.org/docs/advanced-features/custom-error-page 에러 페이지를 서버에서 매번 렌더링 하는 것은 Next.js 서버에 과부화를 줄 수 있다. 이를 방지하기 위해 별도의 파일을 생성하지 않아도 되도록, 넥

intrepidgeeks.com

 

'Development > React.js' 카테고리의 다른 글

next - getStaticProps  (0) 2022.04.14
next - Layout  (0) 2022.04.14
next - _document.js  (0) 2022.04.14
next에서의 Data Fetching  (0) 2022.04.14
next.config.js 로 Rewrite 하기  (0) 2022.04.14