小程序页面路由

小程序页面路由注意事项?

首先要明白 open-type 的几种方式

open-type 有效值:

说明
navigate 对应 wx.navigateTo 的功能
redirect 对应 wx.redirectTo 的功能
switchTab 对应 wx.switchTab 的功能
reLaunch 对应 wx.reLaunch 的功能
navigateBack 对应 wx.navigateBack 的功能

代码中我们将三种个跳转方式进行实验

1
2
3
4
5
<view>
<navigator url="/page/profile/profile">跳转到新页面</navigator>
<navigator url="/page/profile/profile" open-type="redirect">在当前页打开</navigator>
<navigator url="/page/profile/profile" open-type="switchTab">切换到首页Tab</navigator>
</view>

其中注意事项为:

  1. 所有路由的页面都要在 app.json中进行注册;
  2. navigateredirect只能跳转到非注册tabBar的页面;
  3. switchTab只能跳转到注册过tabBar的页面。
分享到