0👍
You can use a condition to check the route name using useRoute and then make an API call. Since pages/[category]/index.vue and pages/[id].vue are two different routes with their own unique route names.
<script setup>
const route = useRoute();
const myCategories = ref([]);
//you can check exact route details from vue devtools extension's routes section.
if(route.name == 'pages-category'){
const { data:allCategories } = await useFetch('/api/get-categories/');
myCategories.value = allCategories;
}
</script>
- [Vuejs]-Trying to use Virtual Scroller in Vue 3 But the items are buffering
- [Vuejs]-Tailwind CSS with Nuxt3 grow text-area size dynamically
Source:stackexchange.com