You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there! I have this search functionality implementaion going on while doing it am encountering this little problem where I do set search params in actions through form but at the same time when I submit & want to retrieve the same search param in load function it returns null, Here's what I am doing currently:
//+page.server.ts
export const load = (async ({ locals, fetch,url }) => {
console.log(url)
let req = await fetch(`/api/data?query=${JSON.parse(url.searchParams.get('query') as string)}`);
let res = await req.json();
return {
payload: res
};
}) satisfies PageServerLoad;
export const actions={
search: async({request,url})=>{
throw redirect(303,`/home?query=${(await request.formData()).get('input')}`)
}
}
Above solution works but its clearly unnecessary and not practical .
Want to achieve this :
//+page.server.ts
export const load = (async ({ locals, fetch,url }) => {
console.log(url)
let req = await fetch(`/api/data?query=${JSON.parse(url.searchParams.get('query') as string)}`);
let res = await req.json();
return {
payload: res
};
}) satisfies PageServerLoad;
export const actions={
search: async({request,url})=>{
let id=(await request.formData()).get('input') as string
url.searchParams.set('query','id')
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there! I have this search functionality implementaion going on while doing it am encountering this little problem where I do set search params in actions through form but at the same time when I submit & want to retrieve the same search param in load function it returns null, Here's what I am doing currently:
Above solution works but its clearly unnecessary and not practical .
Want to achieve this :
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions