Query Params in `opengraph-image`
Unanswered
Vespid wasp posted this in #help-forum
Vespid waspOP
Can I access query params in
http://localhost:3000/accounts/[uuid]/opengraph-image/?example=10
The docs don't seem to mention this, and trying to access
opengraph-image like so:http://localhost:3000/accounts/[uuid]/opengraph-image/?example=10
The docs don't seem to mention this, and trying to access
searchParams prop just like in page.tsx is undefined for me:export default async function OpengraphImage({
params,
searchParams,
}: {
params: { account: string }
searchParams: { chainId: string }
}) {
console.log({ searchParams }) // undefined14 Replies
@Vespid wasp Can I access query params in `opengraph-image` like so:
http://localhost:3000/accounts/[uuid]/opengraph-image/?example=10
The docs don't seem to mention this, and trying to access `searchParams` prop just like in page.tsx is `undefined` for me:
export default async function OpengraphImage({
params,
searchParams,
}: {
params: { account: string }
searchParams: { chainId: string }
}) {
console.log({ searchParams }) // undefined
are you using app router or page router?
if its app router, it should be name exported as
if its app router, it should be name exported as
GETVespid waspOP
I am using app router
@Vespid wasp I am using app router
export async function GETVespid waspOP
Bit confused - you mean replace
Doing that does not get me the query params
export default async function OpengraphImage with export async function GET?Doing that does not get me the query params
try this
export async function GET(req: NextRequest, {
params,
}: {
params: { uuid: string }
}) {
const searchParams = req.nextUrl.searchParams;
const example = searchParams.get("example")
console.log({ example }) // undefined
}Vespid waspOP
export default async function GET(
req: NextRequest,
{
params,
}: {
params: { account: string }
},
) {well the file name should be route.ts
so app/accounts/[account]/opengraph-image/route.ts
export async function GET(req: NextRequest, {
params,
}: {
params: { account: string }
}) {
const searchParams = req.nextUrl.searchParams;
const example = searchParams.get("example")
console.log({ example }) // undefined
}oh nm you want to use og image
Vespid waspOP
Yes
seem like its not possible to get the query param in opengraph-image
Vespid waspOP
Okay, thank you for the help