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

bookAdding Metadata to Pages

Deslize para mostrar o menu

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?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 16

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Seção 1. Capítulo 16
some-alt