#Using NextJS 13 App Router, how do I access the query params in the request, on server side?

10 messages · Page 1 of 1 (latest)

outer imp
#

I don't know what I'm missing here. I can't find any documentation that shows how to access the query params in the request from within the Page component on server side.

spare lichenBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

outer imp
#

I have this

export default async function Page(req) {

  const { searchParams } = new URL(req.url)

  const token = searchParams.get('token')

  
  return (
    <div>hello</div>
  )
}

but am receiving the error TypeError [ERR_INVALID_URL]: Invalid URL

#

nvm

gaunt peak
outer imp
#

This works

export default async function Page({
  params,
  searchParams,
}: {
  params: { slug: string }
  searchParams: { [key: string]: string | string[] | undefined }
}) {

  console.log(searchParams);

  // const token = searchParams.get('token')

  
  return (
    <div>hello</div>
  )
}
#

Julgers I tried your solution earlier but I get errors about using useSearchParams outside of a client component

gaunt peak
#

that is how to do it on client components

#

what I sent