What is the best way to handle search params in metadata? #58692
Unanswered
JamesSingleton
asked this question in
Help
Replies: 2 comments
-
Hi, I guess so, because during pre-rendering there's no Query Params to be used. At the moment, this page should be rendered on-demand. |
Beta Was this translation helpful? Give feedback.
0 replies
-
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I have a search page where I do
?q=${whatever_the_user_searched}
. I am currently doingHowever, that gives me
Do I need to force it to be dynamic so Next.js just doesn't try to render it statically?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions