小程序开发之组件navigator(页面链接)

时间:2024-04-04 22:41:29

navigator

页面链接。
小程序开发之组件navigator(页面链接)小程序开发之组件navigator(页面链接)

open-type 有效值:

小程序开发之组件navigator(页面链接)

注:
navigator-hover 默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;},
<navigator> 的子节点背景色应为透明色
注:
使用限制

  • 需要用户确认跳转
    (1)从 2.3.0 版本开始,在跳转至其他小程序前,将统一增加弹窗,询问是否跳转,用户确认后才可以跳转其他小程序。如果用户点击取消,则回调 fail cancel。
    (2)每个小程序可跳转的其他小程序数量限制为不超过 10 个
    (3)从 2.4.0 版本以及指定日期(具体待定)开始,开发者提交新版小程序代码时,如使用了跳转其他小程序功能,则需要在代码配置中声明将要跳转的小程序名单,限定不超过 10 个,否则将无法通过审核。该名单可在发布新版时更新,不支持动态修改。配置方法详见 配置。调用此接口时,所跳转的 appId 必须在配置列表中,否则回调 fail appId “${appId}” is not in navigateToMiniProgramAppIdList。

  • 关于调试
    (1)在开发者工具上调用此 API 并不会真实的跳转到另外的小程序,但是开发者工具会校验本次调用跳转是否成功。
    (2)开发者工具上支持被跳转的小程序处理接收参数的调试。

例如:
效果展示


小程序开发之组件navigator(页面链接)

代码

index.wxml
<!-- 
  target 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram 
  url  当前小程序内的跳转链接  
  open-type   跳转方式  navigate/redirect/switchTab/reLaunch/navigateBack/exit
  delta:1  当 open-type 为 'navigateBack' 时有效,表示回退的层数   
  app-id  当target="miniProgram"时有效,要打开的小程序 appId
  path    当target="miniProgram"时有效,打开的页面路径,如果为空则打开首页  
  extra-data  当target="miniProgram"时有效,需要传递给目标小程序的数据,目标小程序可在 App.onLaunch(),App.onShow() 中获取到这份数据。
  version  当target="miniProgram"时有效,要打开的小程序版本,有效值 develop(开发版),trial(体验版),release(正式版),仅在当前小程序为开发版或体验版时此参数有效;如果当前小程序是正式版,则打开的小程序必定是正式版。   
  hover-class 指定点击时的样式类,当hover-class="none"时,没有点击态效果  
  hover-stop-propagation:false  指定是否阻止本节点的祖先节点出现点击态   
  hover-start-time:50   按住后多久出现点击态,单位毫秒   
  hover-stay-time:600   手指松开后点击态保留时间,单位毫秒   
  bindsuccess 当target="miniProgram"时有效,跳转小程序成功 
  bindfail 当target="miniProgram"时有效,跳转小程序失败 
  bindcomplete 当target="miniProgram"时有效,跳转小程序完成 
  aria-label 无障碍访问,(属性)元素的额外描述  
 -->
  <!-- 默认跳转方式navigate -->
  <navigator class='navigator' url="/navigate/navigate?title=navigate" hover-class="navigator-hover">navigate跳转到新页面</navigator>
  <!-- redirect -->
  <navigator class='navigator' url="../redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">redirect跳转在当前页打开</navigator>

index.wxss

.navigator{
  margin-left: 150rpx;
  margin-top: 50rpx;
  height: 100rpx;
  width: 450rpx;
  background-color: lavender;
  display: flex;
  align-items: center;
  justify-content: center;
  color:red;
}

/** 修改默认的navigator点击态 **/
.navigator-hover {
    color:green;
}

navigator.wxml

<!-- navigator.wxml -->
<view> navigator跳转后传过来的值为:{{title}}</view>

navigator.js
Page({
  onLoad: function (options) {
    this.setData({
      title: options.title
    })
  }
})

redirect.wxml

<!-- redirect.wxml -->
<view> redirect跳转后传过来的值为:{{title}}</view>

redirect.js
// redirect.js
Page({
  onLoad: function (options) {
    this.setData({
      title: options.title
    })
  }
})