From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Error page

Error page

Currently, if we have any error thrown by the application, then we have the error getting displayed. However, this is not how you would want your end user to see errors. Ideally, we develop the error pages that are rendered if anything goes wrong by proper error handling. So in Next.js, the rendering of the error page is also taken care of. Just like the fav icon, where we did not write any code for configuring it, instead, we simply had to create the file in specific naming conventions. Similarly, to create the error component, you simply create a file named error.js. And Next.js will automatically render it when there is an error. Let's try it practically. I'll create the error.js file inside the app folder. Now we create the error component. So I'll say export default function error. And let me return a division with an h1 where I say there is an error. Now let's save and check the output. Then we have another error saying error.js must be a client component. The reason for this is…

Contents