navigator-页面连接-经过设置open-type的值来肯定页面的打开方式。小程序
<view class="btn-area">
<navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
<navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
<navigator target="miniProgram" open-type="navigate" app-id="" path="" extra-data="" version="release">打开绑定的小程序</navigator>
</view>微信
open-type 有效值:app
navigate 对应 wx.navigateTo 或 wx.navigateToMiniProgram 的功能
redirect 对应 wx.redirectTo 的功能
switchTab 对应 wx.switchTab 的功能
reLaunch 对应 wx.reLaunch 的功能 1.1.0
navigateBack 对应 wx.navigateBack 的功能 1.1.0
exit 退出小程序,target="miniProgram"时生效 2.1.0url
重定向、转发等各类跳转的区别以下:spa
navigate :用于保留当前页面、跳转到应用内的某个页面,使用 wx.navigateBack能够返回到原页面。对于页面不是特别多的小程序,一般推荐使用 wx.navigateTo进行跳转, 以便返回原页面,以提升加载速度。当页面特别多时,则不推荐使用。内存
redirect :当页面过多时,被保留页面会挤占微信分配给小程序的内存,或是达到微信所限制的 5 层页面栈。这时,应该考虑选择 wx.redirectTo。wx.redirectTo()用于关闭当前页面,跳转到应用内的某个页面。这样的跳转,能够避免跳转前页面占据运行内存,但返回时页面须要从新加载,增长了返回页面的显示时间。开发
reLaunch : wx.reLaunch()与 wx.redirectTo()的用途基本相同, wx.reLaunch()先关闭了内存中全部保留的页面,再跳转到目标页面get
switchTab : 对于跳转到 tab bar 的页面,最好选择 wx.switchTab(),它会先关闭全部非 tab bar 的页面。其次,也能够选择 wx.reLaunch(),它也能实现从非 tab bar 跳转到 tab bar,或在 tab bar 间跳转,效果等同 wx.switchTab()。使用其余跳转 API 来跳转到 tab bar,则会跳转失败it
navigateBack: 用于关闭当前页面,并返回上一页面或多级页面。开发者可经过 getCurrentPages() 获取当前的页面栈,决定须要返回几层。这个 API 须要填写的参数只有 delta,表示要返回的页面数。若 delta 的取值大于现有可返回页面数时,则返回到用户进入小程序的第一个页面。当不填写 delta 的值时,就默认其为 1(注意,默认并不是取 0),即返回上一页面。io