Learn/Next.js/Chapter 4

Chapter 4 of 21

Continue learning Next.js step by step.

19%
Chapter 4

Pages & Layouts

Learn how pages and layouts are created in Next.js.

Theory

A page.tsx file defines the UI for a route. A layout.tsx file allows UI to be shared between multiple pages. Layouts are useful for elements such as navigation bars, sidebars and footers.

Example

export default function AboutPage() {
  return (
    <main>
      <h1>About Us</h1>
      <p>Welcome to our website.</p>
    </main>
  );
}

Output

The About page renders the heading and paragraph.

Practice

Create a shared layout containing a navigation bar.

Interview Questions

1

What is a page.tsx file?

2

What is a layout in Next.js?

3

Why are layouts useful?

Quick Quiz

Which option best describes this chapter?

A.Shared UI structure
B.Database table
C.API server
D.CSS compiler