Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Adding Metadata to Pages | Section
Building Web Apps with Next.js

bookAdding Metadata to Pages

Veeg om het menu te tonen

Adding Metadata to Pages

In real applications, pages need more than just content. They also include metadata such as the page title and description. This information is important for search engines, browser tabs, and sharing links.

Next.js provides a simple way to define metadata directly inside your pages and layouts.

Adding Metadata to a Page

You can define metadata by exporting a metadata object from your page file:

export const metadata = {
  title: "About Page",
  description: "Learn more about our company",
};

export default function AboutPage() {
  return <h1>About</h1>;
}

This sets the page title and description automatically.

Adding Metadata in Layouts

You can also define metadata in a layout:

export const metadata = {
  title: "My App",
  description: "A Next.js application",
};

export default function RootLayout({ children }) {
  return (
    <html>
      <body>{children}</body>
    </html>
  );
}

This metadata applies to all pages inside the layout.

How Metadata Works

Metadata can be defined at different levels of your application. When you define metadata inside a layout, it applies to all pages wrapped by that layout. However, if a page defines its own metadata, it overrides the layout values. This allows you to set global defaults while still customizing individual pages when needed.

Why Metadata Matters

Metadata controls how your page appears in the browser, including the title shown in the tab. It also plays an important role in search engine optimization, helping your content appear correctly in search results. In addition, metadata improves how your pages look when shared as links, making your application more professional and easier to understand.

question mark

How do you define metadata for a page in Next.js?

Selecteer het correcte antwoord

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 16

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 1. Hoofdstuk 16
some-alt