feat: RouterStack
Some checks failed
CI / cache-and-install (push) Failing after 1m1s

This commit is contained in:
严浩
2024-08-08 15:13:35 +08:00
parent 5c11b15c1b
commit 2798254dab
18 changed files with 272 additions and 308 deletions

View File

@ -1,15 +0,0 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<style>
@media (min-width: 1024px) {
.about {
min-height: 100vh;
display: flex;
align-items: center;
}
}
</style>

View File

@ -1,12 +1,13 @@
<script setup lang="ts">
import TheWelcome from '../components/TheWelcome.vue'
definePage({
alias: '/',
alias: '/'
})
</script>
<template>
<main>
<TheWelcome />
</main>
<div class="flex gap-2">
<t-button @click="$router.push({ name: 'Page1' })">ToPage1</t-button>
<t-button @click="$router.push({ name: 'Page2' })">ToPage2</t-button>
<t-button @click="$router.push({ name: 'Page3' })">ToPage3</t-button>
</div>
</template>

10
src/pages/page-1.vue Normal file
View File

@ -0,0 +1,10 @@
<template>
<div>
<t-button @click="$router.back()">back()</t-button>
</div>
<div class="h-2" />
<div class="flex gap-2">
<t-button @click="$router.push({ name: 'Page2' })">ToPage2</t-button>
<t-button @click="$router.replace({ name: 'Page2' })">ReplaceToPage2</t-button>
</div>
</template>

31
src/pages/page-2.vue Normal file
View File

@ -0,0 +1,31 @@
<template>
<!-- <VanButton @click="backToHome">Back to Home</VanButton> -->
<div class="flex gap-2">
<t-button @click="$router.go(-1)">go(-1)</t-button>
<t-button @click="$router.go(-2)">go(-2)</t-button>
</div>
</template>
<script setup lang="ts">
import { router } from '@/router';
function backToHome() {
console.log('router.options.history.state.back :>> ', router.options.history.state.back);
const backToName = 'IndexPage';
console.log('backToName :>> ', backToName);
let backCount = 0;
/* for (let i = router.stack.currentStackIndex - 1; i >= 0; i--) {
if (router.stack.list[i].name === backToName) {
backCount = router.stack.currentStackIndex - i;
break;
}
} */
console.log('backCount :>> ', backCount);
}
onMounted(() => {
// console.log('router.currentRoute.value.from :>> ', router.currentRoute.value.from);
// backToHome()
})
</script>

1
src/pages/page-3.vue Normal file
View File

@ -0,0 +1 @@
<template>page-3</template>