1.uni.navigateTo()
保留当前页面,跳转到应用内的某个页面,使用 uni.navigateBack() 可以返回到原页面
uni.navigateTo({
url: 'test?id=1'//多个参数通过&拼接
});
在跳转页面通过onLoad接受参数
export default {
onLoad(option) { //option为对象类型
console.log(option.id);
}
}
2.uni.redirectTo()
关闭当前页面,跳转到应用内的某个页面。
uni.redirectTo({
url: 'test?id=1'
});
3.uni.reLaunch()
关闭所有页面,打开到应用内的某个页面。
uni.reLaunch({
url: 'test?id=1'
})
在跳转页面通过onLoad接受参数
export default {
onLoad(option) { //option为对象类型
console.log(option.id);
}
}
4.uni.switchTab()
跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面。
uni.switchTab({
url: '/pages/index/index'
});
在pages.json中
{
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
},{
"pagePath": "pages/other/other",
"text": "其他"
}]
}
}
5.uni.navigateBack()
关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。
// 此处是A页面
uni.navigateTo({
url: 'B?id=1'
});
// 此处是B页面
uni.navigateTo({
url: 'C?id=1'
});
// 在C页面内 navigateBack,将返回A页面
uni.navigateBack({
delta: 2
});