外观
openPage 页面跳转
约 215 字小于 1 分钟
2024-01-01
介绍
提供统一的页面跳转功能,支持多种跳转方式。
openPage(url: string, linkType?: string): void
- 参数
- url: 页面路径
- linkType: 跳转类型,可选值:'navigateTo'、'redirectTo'、'reLaunch'、'switchTab',默认为 'navigateTo'
- 返回值
<void>无
示例代码
<template>
<view>
<text>页面跳转示例</text>
<button @click="navigateToPage">navigateTo跳转</button>
<button @click="redirectToPage">redirectTo跳转</button>
<button @click="reLaunchToPage">reLaunch跳转</button>
<button @click="switchTabToPage">switchTab跳转</button>
</view>
</template>
<script setup lang="uts">
import { openPage } from '@/uni_modules/uview-unix'
// 保留当前页面,跳转到应用内的某个页面
const navigateToPage = () => {
openPage('/pages/detail/index', 'navigateTo')
}
// 关闭当前页面,跳转到应用内的某个页面
const redirectToPage = () => {
openPage('/pages/detail/index', 'redirectTo')
}
// 关闭所有页面,打开到应用内的某个页面
const reLaunchToPage = () => {
openPage('/pages/home/index', 'reLaunch')
}
// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
const switchTabToPage = () => {
openPage('/pages/index/index', 'switchTab')
}
</script>