Create an Error.tsx Component for Route Errors in Next.js
📖 Scenario: You are building a Next.js app that needs a friendly error page for route errors like 404 or 500.This page should show a clear message and a button to go back home.
🎯 Goal: Build an Error.tsx component that displays the error statusCode and a message. Include a button that navigates back to the homepage.
📋 What You'll Learn
Create a functional React component named
Error in Error.tsx.Accept a prop called
statusCode of type number.Display the
statusCode and a friendly error message.Add a button that uses Next.js
useRouter to navigate back to the homepage when clicked.Use semantic HTML and accessible attributes.
💡 Why This Matters
🌍 Real World
Error pages improve user experience by clearly showing when something goes wrong and guiding users back to safety.
💼 Career
Creating accessible and user-friendly error components is a common task for frontend developers working with Next.js or React.
Progress0 / 4 steps