Skip to main content
InterviewHubPRO
Section Overview
Q20

Question 20 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

40%
Next.js & App Router (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Error Handling in App Router: `error.tsx`, `global-error.tsx`, and `reset()`.

senior LevelCode ExampleRoutingSystem Design

In Simple Words:

  • error.tsx: Must be a Client Component ('use client'). Automatically wraps the route's page.tsx in a React Error Boundary.
    tsx
    'use client';
    export default function Error({ error, reset }: { error: Error; reset: () => void }) {
      return (
        <div>
          <h2>Something went wrong!</h2>
          <button onClick={() => reset()}>Try again</button>
        </div>
      );
    }
    
  • global-error.tsx: Catches errors inside the Root Layout (app/layout.tsx). Must define its own <html> and <body> tags.