ReactJS

generateMetadata function in NEXT JS  


What is metadata?

Metadata on web pages plays a crucial role. It describes the page's content and includes keywords related to it. Search engines often display this metadata in their results, making its accuracy and detail essential for attracting users to a site. Typically, this information is presented through meta tags.

Static Meta Data

import type { Metadata } from 'next'; // Static metadataexport const metadata: Metadata = { title: '...',};

Dynamic Meta Data

import type { Metadata } from 'next'; // Dynamic metadataexport async function generateMetadata({ params }): Promise<Metadata> { return { title: '...', };}

 

The metadata object and the generateMetadata function can only be used in Server Components. It is not allowed to export both the metadata object and the generateMetadata function within the same route segment.

Dynamic metadata, which relies on dynamic data such as current route parameters or external API data, can be configured by exporting a generateMetadata function that returns a Metadata object.

 

Ready to transform your business with our technology solutions? Contact Us today to Leverage Our ReactJS Expertise.

0

React

Related Center Of Excellence