#Adding custom title to a client component (v13.2.4)

3 messages · Page 1 of 1 (latest)

novel bridge
#

I want to add a custom title to a client component based in the searchParams for the page but since it's a client component I cannot use the new metadata API in the page.tsx and I was thinking if there is some new way to add title to client component since head.tsx files are deprecated.

I've also tried using generateMetadata({ searchParams }) in the layout.tsx file where the component is used but the searchParams is undefined.


export async function generateMetadata({
  searchParams
}: {
  searchParams?: ReadonlyURLSearchParams;
}): Promise<Metadata> {
  const username = searchParams?.get('username');
  return { title: username ? `Viewing ${username}'s Profile` : 'Viewing Profile' };
}

but the searchParams parameter is always undefined. I also checked the docs to make sure I was the function appropriately and the docs also seems to be using searchParams in similar way.

Reference to docs: https://beta.nextjs.org/docs/api-reference/metadata#generatemetadata

API reference for all metadata options for SEO configuration.

novel bridge
#

should I just continue using the deprecated head.tsx?

tired tundra
#

I've also tried using generateMetadata({ searchParams }) in the layout.tsx file where the component is used but the searchParams is undefined.
it sounds like a bug to me