首页代码
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{ title }}</text>
</view>
</view>
<button @tap="routeToA">navigateTo 跳转到 Page A</button>
</template>
<script setup>
const title = ref('首页')
const routeToA = () => {
uni.navigateTo({
url: '/pages/page-a/page-a'
})
}
</script>
page-a 代码
<template>
<h1 style="text-align: center; height: 200rpx;">Page A</h1>
<button @tap="routeToB">navigateTo 跳转到 Page B</button>
</template>
<script setup>
const routeToB = () => {
uni.navigateTo({
url: '/pages/page-b/page-b'
})
}
</script>
page-b 代码
<template>
<h1 style="text-align: center; height: 200rpx;">Page B</h1>
<button @tap="back">返回(navigateBack)</button>
</template>
<script setup>
const back = () => {
// 返回上一页,期望返回 page-a,实际返回 index
uni.navigateBack()
}
</script>