1.navigator组件跳转
url:应用内的跳转链接,值为相对路径或绝对路径,不加.vue后缀
open-type:跳转方式
<template>
<view>
<view class="page-body">
<view class="btn-area">
<navigator url="navigate/navigate?title=navigate" hover-class="navigator-hover">
<button type="default">跳转到新页面</button>
</navigator>
<navigator url="redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">
<button type="default">在当前页打开</button>
</navigator>
<navigator url="/pages/tabBar/extUI/extUI" open-type="switchTab" hover-class="other-navigator-hover">
<button type="default">跳转tab页面</button>
</navigator>
</view>
</view>
</view>
</template>
2.调用api跳转
uni.navigateTo(OBJECT)
保留当前页面,跳转到应用内的某个页面。
uni.navigateTo({
url: 'test?id=1&name=uniapp'
});
注意:
- 页面跳转路径有层级限制,不能无限制跳转新页面
- 跳转到 tabBar 页面只能使用 switchTab 跳转
- 路由API的目标页面必须是在pages.json里注册的vue页面。
uni.switchTab(OBJECT)
跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面。
uni.switchTab({
url: '/pages/index/index'
});
uni.redirectTo(OBJECT)
关闭当前页面,跳转到应用内的某个页面。
uni.redirectTo({
url: 'test?id=1'
});
uni.reLaunch(OBJECT)
关闭所有页面,打开到应用内的某个页面。
uni.reLaunch({
url: 'test?id=1'
});
uni.navigateBack(OBJECT)
关闭当前页面,返回上一页面或多级页面。
// 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码
// 此处是A页面
uni.navigateTo({
url: 'B?id=1'
});
// 此处是B页面
uni.navigateTo({
url: 'C?id=1'
});
// 在C页面内 navigateBack,将返回A页面
uni.navigateBack({
delta: 2
});
Tips:
- navigateTo, redirectTo 只能打开非 tabBar 页面。
- switchTab 只能打开 tarbar 页面。
- reLaunch 可以打开任意页面。
- 页面底部的 tarBar 由页面决定,即只要是定义为tarBar 的页面,底部都有tarBar 。
- 不能在App.vue里面进行页面跳转。
- H5端页面刷新之后页面栈会消失,此时navigateBcak不能返回,如果一定要返回可以使用history.back().