params is an empty object
Answered
Sage Thrasher posted this in #help-forum
Sage ThrasherOP
Logs:
As you can see by the URL, the params are there
Code:
{}
Server {}
GET /servers/guild_add?code=45DDtkqa08lE2wBZfHyYIzzE5y&state=%252F&guild_id=1132739446215815248&permissions=1 307 in 664msAs you can see by the URL, the params are there
Code:
import { redirect } from 'next/navigation';
export default async function Page({ params }: { params: { guild_id: string, state: string; } }) {
console.log(params);
if (params.guild_id) {
return redirect(`/servers/${params.guild_id}/edit`);
} else {
return redirect('/');
}
}Answered by James4u
export default function Page({
params,
searchParams,
}: {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
}) {
if (params.guild_id) {
return redirect(`/servers/${searchParams.guild_id}/edit`);
} else {
return redirect('/');
}
}17 Replies
@Sage Thrasher you are trying to get search param right?
https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional
params.guild_id is slug in dynamic routinghttps://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional
check out this link
@James4u <@726059166875254856> you are trying to get search param right? `params.guild_id` is slug in dynamic routing
https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional
Sage ThrasherOP
im trying to get both state and guild_id.
ill check this link out now
ill check this link out now
/servers/guild_add?code=45DDtkqa08lE2wBZfHyYIzzE5y&state=%252F&guild_id=1132739446215815248&permissions=1this must be the link you are hitting right?
you should get
you should get
guild_id from searchParams@James4u this must be the link you are hitting right?
you should get `guild_id` from searchParams
Sage ThrasherOP
im getting nothing but an empty object
i tried removing
state to see if that was causing itshwo me your code
Sage ThrasherOP
@Sage Thrasher use searchParam
did you check the link I shared?
Sage ThrasherOP
i said i was checking it but you replied saying i should receive the guild_id, i didnt know if you meant with my current code or post implementing searchparams
export default function Page({
params,
searchParams,
}: {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
}) {
if (params.guild_id) {
return redirect(`/servers/${searchParams.guild_id}/edit`);
} else {
return redirect('/');
}
}Answer
try this out
@Sage Thrasher i said i was checking it but you replied saying i should receive the guild_id, i didnt know if you meant with my current code or post implementing searchparams
I only said you should use searchParams instead of params
@James4u I only said you should use searchParams instead of params
Sage ThrasherOP
works, thanks!
good to hear that!