After receiving a link from the server to download the file, the user initiates the function to begin downloading. Once the file has finished downloading, the user will be redirected to the main page.
<script setup lang="ts">
const goToMain = (time: number) => {
setTimeout(() => {
router.push({
name: ERouteName.PAGE_HOME
})
}, time)
}
try {
const { query } = router.currentRoute.value
const { url } = await clientStore.uploadAppealFile(query.file_id as string)
if (url) {
const link = document.createElement('a')
link.href = url
link.click()
goToMain(3000)
}
} catch (error) {
goToMain(0)
}
</script>
I am currently using a timer to switch to the main page, but I would prefer for the goToMain() function to execute after the file has finished loading.