Fix: 修正重定向逻辑 & 使用Pinia管理状态
This commit is contained in:
@ -1,15 +1,48 @@
|
||||
<template>
|
||||
<div>Redirecting...</div>
|
||||
<v-container class="d-flex justify-center align-center" style="min-height: 50vh;">
|
||||
<div class="text-center">
|
||||
<v-progress-circular
|
||||
color="primary"
|
||||
indeterminate
|
||||
size="64"
|
||||
width="6"
|
||||
/>
|
||||
<div class="text-h6 mt-4 text-primary">
|
||||
{{ $t('loading') }}...
|
||||
</div>
|
||||
</div>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
onMounted(() => {
|
||||
// Redirect to the calculators page
|
||||
router.push('/calculators/paper-tube-weight')
|
||||
onMounted(async () => {
|
||||
// 等待路由完全准备好
|
||||
await router.isReady()
|
||||
|
||||
// 检查是否是直接访问首页
|
||||
const isDirectAccess = route.path === '/' && !document.referrer.includes(window.location.origin)
|
||||
|
||||
let targetPath = '/calculators/paper-tube-weight' // 默认路径
|
||||
|
||||
if (!isDirectAccess) {
|
||||
// 如果不是直接访问,尝试恢复上次的路径
|
||||
const lastRoute = sessionStorage.getItem('lastRoute')
|
||||
const savedPath = localStorage.getItem('lastPath')
|
||||
targetPath = lastRoute || savedPath || targetPath
|
||||
}
|
||||
|
||||
// 使用 replace 避免在历史记录中留下首页
|
||||
router.replace(targetPath)
|
||||
})
|
||||
</script>
|
||||
|
||||
<route lang="yaml">
|
||||
meta:
|
||||
layout: CalculatorLayout
|
||||
</route>
|
||||
|
||||
Reference in New Issue
Block a user