navigateTo and route query in Nuxt.navigateTo, the URL in the browser changes, but the useRoute() composable might not immediately reflect these changes in its query property.route.query, create a computed property that will reactively update when the route changes. This approach is suggested in the Stack Overflow answer:watch option in useFetch:useFetch composable provides a watch option that can be used to trigger refetches when specified values change. This is documented in Nuxt's data fetching guide:useFetch call reacts to changes in the route query, even when using navigateTo for client-side navigation.navigateTo, you might want to await the navigation before calling refresh():useFetch call react properly to route query changes, even when using navigateTo for client-side navigation.route.queryrefresh() const routeQuery = computed(() => route.query)
const { data, refresh } = await useFetch<GameDeal[]>(`/api/browsedeals`, {
query: routeQuery
}); const route = useRoute()
const { data, refresh } = await useFetch<GameDeal[]>(`/api/browsedeals`, {
query: route.query
});
watch(() => route.query, () => refresh()) const route = useRoute()
const { data, refresh } = await useFetch<GameDeal[]>(`/api/browsedeals`, {
query: route.query,
watch: [route.query]
}); const route = useRoute()
const { data, refresh } = await useFetch(() => `/api/browsedeals?${new URLSearchParams(route.query).toString()}`, {
watch: [route.query]
});async function refreshDeals() {
await navigateTo({
path: '/browse',
query: {
storeID: storeIDParam.value,
title: title.value,
sortBy: sortBy.value,
desc: desc.value,
pageNumber: currentPage.value,
}
});
await refresh();
}