#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)
🔎 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)
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
const { searchParams } = new URL(req.url)~
const searchParams = useSearchParams();
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
yeah I did not read your question correctly
that is how to do it on client components
what I sent