In Next.js, when using the App Router, you can define metadata for your application using the Metadata API. This can be done in two ways: Config-based Metadata and File-based Metadata.
Config-based Metadata allows you to export a static metadata object or a dynamic generateMetadata function in a layout.js or page.js file. Here's an example of how you can define static metadata:
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: '...',
description: '...',
}
export default function Page() {}
Source (https://nextjs.org/docs/app/building-your-application/optimizing/metadata)
File-based Metadata involves adding static or dynamically generated special files to route segments. Once a file is defined, Next.js will automatically serve the file and update the relevant head elements with the correct metadata. Source (https://nextjs.org/docs/app/api-reference/file-conventions/metadata)
It's important to note that you should not manually add <head> tags such as <title> and <meta> to root layouts. Instead, you should use the Metadata API which automatically handles advanced requirements such as streaming and de-duplicating <head> elements. Source (https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#modifying-head)