小程序的路由
小程序的路由有标签式的还有代码式的
标签式
格式:<navigator url="要跳转的路径" open-type="跳转方式"></navigator>
open-type值的类型有:
1.navigate 默认值,即只能打开非tabBar页面,有回退按钮
相当于this.$router.push('路径')
2.switchTab 只能跳转到tabBar页面
3.reLaunch 即能跳转到tabBar页面,也能跳转到非tabBar页面
4.redirect 只能跳转到非tabBar页面,但没有回退按钮 相当于vue中this.$router.replace('路径 ')
代码式
JS模式路由类似于Vue中的编程式导航 例如:this.$router.push()
wx.navigateTo({
url: '/pages/jd_market/jd_market',
})
wx.switchTab({
url: `/pages/shopping/shopping`,
})
wx.reLaunch({
url: 'url',
})
跳转传参
拿代码式来说,如果是从tabBar页面传参到非tabBar页面怎么传
wx.navigateTo({
url: 'url'+int,
})
如果是从从tabBar页面传参到tabBar页面呢?
大家可能会想到
wx.switchTab({
url: url`,
})
它确实可以跳转到tabBar页面但是!它没办法传参所以用下面方法,
这样就行啦
wx.reLaunch({
url: 'url'+int,
})