-
Hi there, I have an application which has a /transactions/:id route with vue router that renders the following: When I manually enter the url everything goes well because the However when I trigger a manual navigation clicking on a link (router.push) the query is not updated. This is because vue-router re-uses the same component for efficiency. https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes This prevents the queries to be executed on This is the code of the component: <template>
<aside v-if="status === 'success'">
<AcHeading>Transaction details</AcHeading>
<AcParagraph margin="20px 0">{{data?.id}}</AcParagraph>
<AcParagraph>{{data?.amount}} - {{data?.currency}}</AcParagraph>
</aside>
</template>
<script setup lang="ts">
import transactionsRepository from 'repositories/transactions.repository';
import { AcHeading, AcParagraph } from '@apto-payments/apto-core-vue';
import { useQuery } from '@tanstack/vue-query';
import { useRoute } from 'vue-router';
const route = useRoute();
const id = route.params.id as string;
const { status, data } = useQuery({
queryKey: ["transactions", "details", id],
queryFn: () => transactionsRepository.details({ id }),
});
</script>
<style scoped>
...
</style> So the problem here is how to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Ok, the solution is to add a :key property to parent router component. https://vueschool.io/lessons/how-to-rerender-components-when-vue-router-params-changes |
Beta Was this translation helpful? Give feedback.
Ok, the solution is to add a :key property to parent router component.
https://vueschool.io/lessons/how-to-rerender-components-when-vue-router-params-changes