微信小程序页面跳转方法总结
- 利用小程序提供的 API 跳转:
wx.navigateTo({
url: 'page/home/home?user_id=111'
})
wx.navigateTo({
url: 'page/home/home?user_id=111'
})
wx.navigateTo({
url: 'page/detail/detail?product_id=222'
})
wx.navigateBack({
delta: 2
})
wx.redirectTo({
url: 'page/home/home?user_id=111'
})
wx.switchTab({
url: 'page/index/index'
})
wx.reLanch({
url: 'page/home/home?user_id=111'
})
- wxml 页面组件跳转(可以通过设置open-type属性指明页面跳转方式):
// navigator 组件默认的 open-type 为 navigate
<navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
// redirect 对应 API 中的 wx.redirect 方法
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
// switchTab 对应 API 中的 wx.switchTab 方法
<navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
// reLanch 对应 API 中的 wx.reLanch 方法
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">关闭所有页面,打开到应用内的某个页面</navigator>
// navigateBack 对应 API 中的 wx.navigateBack 方法
<navigator url="/page/index/index" open-type="navigateBack" hover-class="other-navigator-hover">关闭当前页面,返回上一级页面或多级页面</navigator>
引用地址 https://www.cnblogs.com/yaoyuqian/p/7967472.html