generateMetadata
not returning params as expected
#47003
Replies: 6 comments 2 replies
-
I got the same issue. |
Beta Was this translation helpful? Give feedback.
-
@fredrivett Looks like you were using the wrong version of Next.js. In v13.1.6 (January 28) it looked like this The PR to implement generateMetadata, #45401 was merged Feb 1. So Testing it in Next.js 13.3.0 seems to be working as expected |
Beta Was this translation helpful? Give feedback.
-
You must upgrate your next version ( https://nextjs.org/docs/pages/building-your-application/upgrading/version-13 )
and enable the |
Beta Was this translation helpful? Give feedback.
-
I am on Next.js 13.4.19 and still do not have the parameter. This is what I see if I try to access /blog/[slug]?a=1 (mysite.com/blog/my-article?a-1) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Use middleware to set your queryParams to cookie. import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const YOUR_VALUE = request.nextUrl.searchParams.get("YOUR_VALUE");
const response = NextResponse.next();
if (refId) {
response.cookies.set("temp-YOUR_VALUE", YOUR_VALUE, {
maxAge: 60,
httpOnly: true,
path: "/",
});
}
return response;
}
export const config = {
matcher: "/",
}; then export async function generateMetadata(): Promise<Metadata> {
const cookieStore = await cookies();
const YOUR_VALUE = cookieStore.get("YOUR_VALUE")?.value;
} |
Beta Was this translation helpful? Give feedback.
-
I'm in the process of upgrading to the new
/app
directory setup, and want to implement dynamic meta data for a blog post. I've been following the Metadata guide forgenerateMetadata
, but I can't seem to reproduce the expected behaviour.Specifically, I'm not seeing any props passed through to the
generateMetadata
function.I have the following page at
src/app/products/[id]/page.tsx
:When I go to the page http://localhost:3000/products/myproduct/ in my browser, I see the following logs in the server console:
Component: props { params: { id: 'myproduct' }, searchParams: {} } generateMetadata: props {}
As you can see, the component is receiving the props as expected, with
params
containing the correct param forid
, butgenerateMetadata
doesn't receive them, despite the docs seeming to state it should.I'm probably doing something obvious wrong but having spent an hour on this I can't figure it out, so any help or tips would be much appreciated.
I'm on
next
v13.1.6
.Beta Was this translation helpful? Give feedback.
All reactions