logologo
  • AI Tools

    DB Query GeneratorMock InterviewResume BuilderLearning Path GeneratorCheatsheet GeneratorAgentic Prompt GeneratorCompany ResearchCover Letter Generator
  • XpertoAI
  • MVP Ready
  • Resources

    CertificationsTopicsExpertsCollectionsArticlesQuestionsVideosJobs
logologo

Elevate Your Coding with our comprehensive articles and niche collections.

Useful Links

  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation
  • About Us

Resources

  • Xperto-AI
  • Certifications
  • Python
  • GenAI
  • Machine Learning

Interviews

  • DSA
  • System Design
  • Design Patterns
  • Frontend System Design
  • ReactJS

Procodebase © 2024. All rights reserved.

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Dynamic Generate Metadata in Next.js 14

author
Generated by
Abhishek Goyan

25/07/2024

Next.js

Sign in to read full article

Next.js 14 introduces a generateMetadata function that allows you to dynamically create metadata for each route. you need to add this to you page.tsx file.

export async function generateMetadata({ params }) { const { slug } = params; const data = await fetchData(slug); //API call to get the data const title = data.title; const description = `Discover insightful information about ${title}. Dive into details and explore more.`; const ogTitle = data.ogTitle || title; const ogDescription = data.ogDescription || description; const twitterTitle = data.twitterTitle || title; const twitterDescription = data.twitterDescription || description; return { title, description, openGraph: { title: ogTitle, description: ogDescription, url: `https://yourwebsite.com/${slug}`, type: 'article', }, twitter: { card: 'summary_large_image', title: twitterTitle, description: twitterDescription, }, }; }

generateMetadata Function: This function fetches page data based on the slug parameter and returns a metadata object with properties like title, description, openGraph, and twitter.

Popular Tags

Next.jsgenerateMetadatametadata

Share now!

Like & Bookmark!

Related Collections

  • Mastering Next.js 14: App Router Deep Dive

    02/10/2024 | Next.js

  • Next.js 14 Performance Mastery

    08/09/2024 | Next.js

Related Articles

  • Adding Dynamic Metadata in Next.js 14

    25/07/2024 | Next.js

  • Understanding Next.js

    28/11/2024 | Next.js

  • Static vs Dynamic Rendering in Next.js 14

    02/10/2024 | Next.js

  • Streaming and Suspense

    02/10/2024 | Next.js

  • Understanding the App Router in Next.js 14

    30/07/2024 | Next.js

  • Mastering Middleware in Next.js 14 App Router

    02/10/2024 | Next.js

  • Image Optimization in Next.js

    08/09/2024 | Next.js

Popular Category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design