Wondering how to get Next.js SEO right without guessing? Set metadata on the server with the metadata object or generateMetadata, and keep pages pre-rendered so titles and descriptions land in the initial HTML.
This page is a spoke of the wider guide to seo for web apps, which covers the bigger picture.
| Item | Value |
|---|---|
| Static metadata | Export a Metadata object from layout.js or page.js |
| Dynamic metadata | Export a generateMetadata function that returns a Metadata object |
| Where the exports run | Server Components only |
| Both exports in one route segment | Not allowed |
| Title template | Requires title.default alongside title.template |
| Conflict with config exports | File-based metadata takes priority |
These points come from the Next.js App Router documentation for generateMetadata and a previous version of the same page. Docs change between releases, so check the source before you rely on them.
Static metadata or generateMetadata?
For a fixed title and description, export a metadata object from a layout.js or page.js file. Next.js then resolves it and creates the relevant head tags for the page, as the App Router docs describe.
When values depend on route parameters, external data or the metadata of parent segments, export generateMetadata instead. It returns a Metadata object, so the output looks the same to a crawler.
The function receives three inputs:
- params: the dynamic route parameters, from the root segment down to the segment being resolved.
- searchParams: the query string values, available only in page.js segments.
- parent: a promise of the metadata already resolved by parent segments, which lets you extend it rather than replace it.
A sensible rule is to reach for the static object whenever nothing varies per request. The docs say metadata that does not depend on runtime information should use the static object rather than the function.
Two practical details help. Identical fetch calls made inside generateMetadata are memoized across layouts, pages and Server Components, so you do not pay for the same request twice. You can also call redirect() and notFound() inside the function, per the same reference.
How rendering decides what crawlers see
Resolving generateMetadata is part of rendering the page. If the page can be pre-rendered and the function adds no dynamic behavior, the resulting metadata is included in the initial HTML.
Otherwise the metadata can be streamed after the initial UI is sent. Pages where a search engine must read the title and description straight away are therefore safest when the metadata stays free of dynamic behavior.

Both the main App Router reference and a newer release of the docs describe this behavior, so the rule is not tied to one version.
Titles: default, template and absolute
The title field accepts a plain string or an object, and the object form is where most sites gain consistency. Three keys matter:
- title.default gives child segments a fallback title when they define none.
- title.template adds a prefix or suffix to titles defined in child segments, such as a site name.
- title.absolute provides a title that ignores any template set in parent segments.
The template applies to child route segments, not to the segment where it is defined. That means a template in a layout does not touch a title set in the page.js of the same segment, and you must add title.default whenever you add a template.
A template also has no effect if the route defines neither a title nor a default. These rules are laid out in the title section of the reference.
Why metadata stays in Server Components
The metadata object and the generateMetadata function are only supported in Server Components. The newer docs explain why: resolving metadata on the server lets Next.js include it in the initial HTML response, according to the newer documentation.
If a page needs interactivity, keep page.tsx as a Server Component and move the client logic into a separate file. The exported metadata then stays valid while the interactive part runs in the browser.
If your pages lean on client-side rendering instead, the guide to react seo explains how that changes what crawlers receive.
Where do sitemaps and file-based metadata fit?
File-based metadata has higher priority than the config exports. If a metadata file and an exported object describe the same thing, the file wins.
The reference pages behind this guide do not describe sitemap file syntax, so this guide leaves it out rather than guess. Check the Next.js file-conventions documentation for the current sitemap format before you build one.
A short checklist before you ship
How much of this matters depends on what you are building, and the explainer on web app vs website helps you judge that. For any project, run through these steps:
- Decide per route whether the metadata is fixed or depends on data.
- Set a default title in the root layout before adding a template.
- Keep page files as Server Components so metadata resolves on the server.
- Avoid dynamic behavior in generateMetadata where the tags must be in the first HTML.
- Look for metadata files that could be overriding your exports.
Frequently asked questions
Can a layout export both metadata and generateMetadata?
Show answer
Not within the same route segment. Choose the static object for values that never change and the function for values that do.
Does fetching data in generateMetadata duplicate requests?
Show answer
Matching fetch requests are memoized across generateMetadata, generateStaticParams, layouts, pages and Server Components. React cache is the option when fetch is not available.
Can I use client hooks in a page that exports metadata?
Show answer
Not in that same file. Put the hooks in a separate Client Component and import it into the Server Component page.
Which wins if a metadata file and an export disagree?
Show answer
The file. File-based metadata overrides both the object and the function.
Can generateMetadata send a visitor elsewhere?
Show answer
Yes. The redirect() and notFound() methods are usable inside it.



