路由
- wx.navigateTo
保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。
wx.navigateTo({
url: 'test?id=1',
events: {
},
...
},
success: function(res) {
res.eventChannel.emit('data', { data: 'test' })
}
})
Page({
onLoad: function(option){
console.log(option.data)
})
}
})
- wx.redirectTo
关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
wx.redirectTo({
url: 'test?id=1'
})
- wx.switchTab
跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
{
"tabBar": {
"list": [{
"pagePath": "index",
"text": "首页"
},{
"pagePath": "other",
"text": "其他"
}]
}
}
wx.switchTab({
url: '/index'
})
- wx.reLaunch
关闭所有页面,打开到应用内的某个页面
wx.reLaunch({
url: 'test?id=1'
})
Page({
onLoad (option) {
console.log(option.query)
}
})
- wx.navigateBack
关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages 获取当前的页面栈,决定需要返回几层。
wx.navigateTo({
url: 'B?id=1'
})
wx.navigateTo({
url: 'C?id=1'
})
wx.navigateBack({
delta: 2
})
路由跳转传参
路由跳转传参可以通过?的方式拼接参数。跳转到指定界面之后,可以在该页面的onLoad方法中的options参数(本身是个对象)拿到路由跳转的参数。