微信小程序頁面跳轉方法總結
- 利用小程序提供的 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