Replies: 2 comments
|
Sorry for the confusion before. Now I've noticed that although the refresh is working properly, there is still an issue when switching routes. 😭 |
|
In current Nuxt 4, both forms are valid. The important distinction is client-side navigation, not SSR. Nuxt now documents the behavior explicitly:
Reference: https://nuxt.com/docs/4.x/api/composables/use-async-data#usage That means removing For a dynamic content page, make the key itself reactive: <script setup lang="ts">
const route = useRoute()
const contentPath = computed(() => route.path)
const { data, status, error } = await useAsyncData(
() => `tools-item:${contentPath.value}`,
() => queryCollection("tools")
.path(contentPath.value)
.first(),
)
</script>Nuxt automatically reruns the handler when a reactive key changes, so no separate For the menu/layout, derive the part that actually controls the query: const section = computed(() =>
route.path.split("/").slice(0, 3).join("/")
)
const { data: items } = await useAsyncData(
() => `tools-menu:${section.value}`,
() => queryCollectionNavigation("tools")
.where("path", "LIKE", `${section.value}%`)
.then(items => items[0]?.children?.[0]?.children ?? []),
)If you intentionally want one stable key instead, watch a getter/ref rather than the entire route proxy: watch: [() => route.path]A few related details matter here:
So the direct answer is: no, If this fixes both refresh and route switching in the reproduction, you can mark it as the accepted answer so the |
Uh oh!
There was an error while loading. Please reload this page.
Hello! Recently, I have been using Nuxt Content. After reading the documentation, I found that both https://nuxt.com/docs/4.x/api/composables/use-async-data and https://content.nuxt.com/docs/utils/query-collection utilize
await useAsyncData. However, when I attempted it, I found that this would cause the data to fail to be retrieved properly during the refresh process. At the same time, I am very puzzled as to why we need toawait useAsyncData?This is the example I am currently working on: saurlax/saurlax-app@0db7648
Before the modification, when you refreshed at the path
/tools/crypto/aes, you wouldn't receive any result. After the modification, everything is back to normal.All reactions