Error Handling
error.js
: 중첩된 경로에서 발생할 수 있는 오류를 처리할 수 있다.
- error.js 파일을 추가하면 Next.js가 자동으로 경로에서 발생하는 오류를 감지하고, 그 오류에 대한 fallback UI를 제공한다.
- 중첩된 경로의 페이지나 컴포넌트에서 발생한 오류에 적절한 UI를 표시한다.
- error.js 파일을 통해 React의 Error Boundary를 자동으로 생성하고, 그 안에서 발생하는 오류를 잡아낸다.
import React from 'react';
export default function ErrorPage({ error }) {
console.error('에러 내용:', error);
return (
<div>
<h2>문제가 발생했습니다!</h2>
<p>{error.message}</p>
<details>
<summary>자세히 보기</summary>
<pre>{error.stack}</pre>
</details>
</div>
);
}
Routing: Error Handling | Next.js
Learn how to display expected errors and handle uncaught exceptions.
nextjs.org
Component – React
The library for web and native user interfaces
react.dev
All Courses – 노마드 코더 Nomad Coders
초급부터 고급까지! 니꼬쌤과 함께 풀스택으로 성장하세요!
nomadcoders.co