05 / 24

Describe page.js.

The page file allows you to define UI that is unique to a route.

  1. 1

    A page is always the leaf of the route subtree.

  2. 2

    A page file is required to make a route segment publicly accessible.

  3. 3

    Pages are Server Components by default, but can be set to a Client Component.

  4. 4

    params and searchParams are optional props received.

Difficulty: 6/10
Topics: App Router Routing, Server vs Client Components, Data Fetching & Caching

Scenario Questions

0-2 years experience
  1. 1

    Imagine you need to add a new '/about' page to our Next.js app. Walk me through where you would create the file in the directory structure, what the file should be named, and how you'd write a basic component inside it to render some static HTML.

  2. 2

    You've just created a new page.js file and you want to add a simple click handler to a button. When you run it, you get an error in the console about useState or event handlers. What's happening here, and how do you fix it?

  3. 3

    We need to build a product detail page where the URL looks like '/products/123'. How would you structure your folders and name your page file to capture that '123' ID, and how do you access that ID inside your component?

2-5 years experience
  1. 1

    You have a page.js that fetches data from an external API. You've made the component async and are using await fetch() directly inside it. However, a teammate points out that this page is blocking the entire render and showing a blank screen while fetching. How would you debug this, and what Next.js features would you introduce to improve the user experience?

  2. 2

    We have a search results page at '/search?q=query'. Inside page.js, we are reading searchParams. We noticed that when the user types a new query and presses enter, the page doesn't seem to update or fetch new data, or it does a full hard reload. How does Next.js handle searchParams in page.js, and how would you ensure the UI updates efficiently without a full page refresh?

  3. 3

    You have a sidebar in layout.js and main content in page.js. You want to trigger a state change in the sidebar when a user clicks a button inside page.js. Since layout.js wraps page.js, how would you handle this state sharing, keeping in mind Server and Client component boundaries?

5-8 years experience
  1. 1

    We are deploying a high-traffic blog where some pages are completely static, but others need real-time comments. How do you configure your page.js files to balance static generation with dynamic runtime data? Specifically, how would you use route segment configs like revalidate or dynamic to optimize TTFB and CDN caching?

  2. 2

    We need to dynamically generate SEO tags (title, description, open-graph images) for our product pages based on data fetched from a CMS. How would you implement this in page.js using generateMetadata? What are the performance implications of fetching the same product data in both generateMetadata and the Page component itself, and how does Next.js optimize this?

  3. 3

    In a complex dashboard with nested routes (e.g., '/dashboard/analytics/realtime'), an API call fails inside the deepest page.js. How do you prevent the entire dashboard from crashing? Walk me through how you'd design the error boundaries using error.js and how they interact with the parent layouts and sibling pages.

8+ years experience
  1. 1

    We have a massive legacy Next.js application using the Pages router (pages/index.tsx with getServerSideProps). We want to migrate to the App Router (app/page.js) incrementally without disrupting our product teams or causing downtime. What is your migration strategy? How do you handle shared state, global layouts, and data-fetching pattern shifts during this transition?

  2. 2

    In a large-scale enterprise application with dozens of federated teams contributing to a single Next.js codebase, we are seeing a massive increase in bundle sizes because teams are putting 'use client' at the top of their page.js files by default. How would you establish architectural guardrails, linting rules, or design patterns to enforce Server-first rendering at the page.js level while still allowing rich interactivity?

Follow-up Questions

  • How does page.js differ from template.js in terms of state preservation during navigation?
  • What is the performance impact of making a page.js an async Server Component versus a Client Component?
  • How does Next.js handle parallel data fetching if you have multiple nested page.js and layout.js files?