普通跳转
javascript
wx.navigateTo({
url: '/pages/xxx/xxx'
})
返回
javascript
wx.navigateBack({})
wx.navigateBack({
delta: 0
})
关闭当前页并跳转
javascript
wx.redirectTo({
url: 'pages/xxx/xxx'
})
切换主菜单
javascript
wx.switchTab({
url: '../store/index'
})
小程序跳转
javascript
wx.navigateToMiniProgram({
appId: 'xxx',
path: 'pages/index/index?phone=' + wx.getStorageSync('phone')
})
小程序跳转传递手机号参数
javascript
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 小程序跳转
wx.showModal({
title: '已迁移至新小程序',
content: '请搜索"xxx"',
showCancel: false,
complete: (res) => {
if (res.confirm) {
wx.navigateToMiniProgram({
appId: 'xxx',
path: 'pages/index/index?phone=' + wx.getStorageSync('phone')
})
}
}
})
},
javascript
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 兼容小程序跳转传递手机号
if(!wx.getStorageSync('phone') && options.phone){
wx.setStorageSync('phone', options.phone)
}
}