2

In my nextjs 15 project with app router. i am trying to add meta details into one of its dynamic route using genrateMetaData function. but somehow its not being rendered in the view source of the page but is visible in the tabs header. this specific issue only arrises in the dynamic routes . in static routes the same function is used and the meta info is visible as expected but same thing is not being achieved in the dynamic routes

i am trying to add meta details into one of its dynamic route using genrateMetaData function. but somehow its not being rendered in the view source of the page but is visible in the tabs header. this specific issue only arrises in the dynamic routes . in static routes the same function is used and the meta info is visible as expected but same thing is not being achieved in the dynamic routes

import CategoryPage from "@/Theme/page-components/Shop/page";
import { notFound } from "next/navigation";

async function getData(category?: string) {
  const url = category
    ? `${process.env.NEXT_PUBLIC_BASE_URL}api/product?category=${category}`
    : `${process.env.NEXT_PUBLIC_BASE_URL}api/product`;

  const res = await fetch(url, { next: { revalidate: 3600 } });

  if (!res.ok) throw new Error("Failed to fetch data");
  const data = await res.json();

  return data;
}

export async function generateMetadata()
//   {
//   params,
// }: {
//   params: Promise<{ category: string }>;
// }): Promise<Metadata> 
{
  // Await the params since they're now a Promise in Next.js 15
  // const resolvedParams = await params;

  // try {
  //   const data = await getData(resolvedParams.category);
  //   const seoSetting = data.seoSetting;


  //   console.log("category page seo",seoSetting)
    return {
      title:  "Shop categriy Fitness",
      description:  "Shop categriy Fitness",
      robots: "index,follow",
    }      
      // openGraph: {
      //   title: seoSetting?.seo_title || "Shop Pulseit Fitness",
      //   description: seoSetting?.seo_description || "Shop Pulseit Fitness",
      //   // Add other OG tags as needed
      // },
      // twitter: {
      //   card: 'summary_large_image',
      //   title: seoSetting?.seo_title || "Shop Pulseit Fitness",
      //   description: seoSetting?.seo_description || "Shop Pulseit Fitness",
      //   // Add other Twitter tags as needed
      // },
  //   };
  // } catch (error) {
  //   console.error("Error generating metadata:", error);
  //   return {
  //     title: "Shop Pulseit Fitness",
  //     description: "Shop Pulseit Fitness",
  //   };
  // }
}

export default async function Page({
  params,
}: {
  params: Promise<{ category: string }>;
}) {
  // Await the params since they're now a Promise in Next.js 15
  const resolvedParams = await params;

  try {
    const data = await getData(resolvedParams.category);
    return <CategoryPage data={data} categorySlug={resolvedParams?.category} />;
  } catch (error) {
    console.log(error);
    notFound();
  }
}
1
  • view-source shows the initial server HTML, but your dynamic route’s metadata is being added/updated after that (RSC streaming or client-side hydration), so it updates the tab title but not view-source. Make generateMetadata await params, keep it server-only, and return cacheable/static data (or precompute it) so the meta is emitted on the server. Commented Aug 9 at 11:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.