N
Nuxt2mo ago
Gobbo

Server doesnt have params when client does

So I'm using useAsyncData to fetch some data, when I navigate to this page via NuxtLink the client makes the request fine but the server doesn't get the params from the id const { id } = route.params; // set on client but not on server by initial load const { data, error } = await useAsyncData<GuildGetResponse>('guild', () => $api(/api/guild/${id}/full)); HOWEVER when i refresh the page the server has access, my thought is that it doesnt have the id as it fetches before page load but surely it works?
No description
4 Replies
Gobbo
Gobbo2mo ago
still not sure whats the cause of this issue
Gobbo
Gobbo2mo ago
Turns out NuxtLayout runs before a page loads, which means it doesnt have the route data properly, https://stackoverflow.com/questions/76127659/route-params-are-undefined-in-layouts-components-in-nuxt-3
Stack Overflow
Route params are undefined in layouts/components in Nuxt 3
I'm having problems with route params being undefined in components/layouts in Nuxt 3. It seems like a bug but it would be such a critical bug, that I almost don't believe it can be a bug. Consider...
wypratama
wypratama2mo ago
I'm not sure if you can destructure route params like that you might need to call route.params.id if you want to get id. Also, you might need to watch id
const { data, error } = await useAsyncData<GuildGetResponse>('guild', () => $api(/api/guild/${id}/full), {watch: [route.params.id]});
const { data, error } = await useAsyncData<GuildGetResponse>('guild', () => $api(/api/guild/${id}/full), {watch: [route.params.id]});
Gobbo
Gobbo2mo ago
good shout didnt try a watch but got it solved :)
Want results from more Discord servers?
Add your server