Next.js Discord

Discord Forum

Query Params in `opengraph-image`

Unanswered
Vespid wasp posted this in #help-forum
Open in Discord
Vespid waspOP
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

14 Replies

Vespid waspOP
I am using app router
@Vespid wasp I am using app router
export async function GET
Vespid waspOP
Bit confused - you mean replace 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