# navigator
基礎(chǔ)庫 1.0.0 開始支持,低版本需做兼容處理。
小程序插件:支持,需要小程序基礎(chǔ)庫版本不低于 2.1.0
微信 Windows 版:支持
微信 Mac 版:支持
微信 鴻蒙 OS 版:支持
渲染框架支持情況:Skyline (使用最新 Nightly 工具調(diào)試)、WebView
# 功能描述
頁面鏈接。
- navigator 在 Skyline 下視為文本節(jié)點(diǎn),只能嵌套文本節(jié)點(diǎn)(如 text),不能嵌套 view、button 等普通節(jié)點(diǎn),如 <button> <navigator>foo</navigator> </button>
- 新增 span 組件用于內(nèi)聯(lián)文本和圖片,如 <span> <image> </image> <navigator>bar</navigator> </span>
# 通用屬性
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 | 最低版本 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| target | string | self | 否 | 在哪個(gè)目標(biāo)上發(fā)生跳轉(zhuǎn),默認(rèn)當(dāng)前小程序 | 2.0.7 | ||||||||||||||||||||||
| |||||||||||||||||||||||||||
| url | string | 否 | 當(dāng)前小程序內(nèi)的跳轉(zhuǎn)鏈接 | 1.0.0 | |||||||||||||||||||||||
| open-type | string | navigate | 否 | 跳轉(zhuǎn)方式 | 1.0.0 | ||||||||||||||||||||||
| |||||||||||||||||||||||||||
| delta | number | 1 | 否 | 當(dāng) open-type 為 'navigateBack' 時(shí)有效,表示回退的層數(shù) | 1.0.0 | ||||||||||||||||||||||
| app-id | string | 否 | 當(dāng)target="miniProgram"且open-type="navigate"時(shí)有效,要打開的小程序 appId | 2.0.7 | |||||||||||||||||||||||
| path | string | 否 | 當(dāng)target="miniProgram"且open-type="navigate"時(shí)有效,打開的頁面路徑,如果為空則打開首頁 | 2.0.7 | |||||||||||||||||||||||
| extra-data | object | 否 | 當(dāng)target="miniProgram"且open-type="navigate/navigateBack"時(shí)有效,需要傳遞給目標(biāo)小程序的數(shù)據(jù),目標(biāo)小程序可在 App.onLaunch(),App.onShow() 中獲取到這份數(shù)據(jù)。詳情 | 2.0.7 | |||||||||||||||||||||||
| version | string | release | 否 | 當(dāng)target="miniProgram"且open-type="navigate"時(shí)有效,要打開的小程序版本 | 2.0.7 | ||||||||||||||||||||||
| |||||||||||||||||||||||||||
| short-link | string | 否 | 當(dāng)target="miniProgram"時(shí)有效,當(dāng)傳遞該參數(shù)后,可以不傳 app-id 和 path。鏈接可以通過【小程序菜單】->【復(fù)制鏈接】獲取。 | 2.18.1 | |||||||||||||||||||||||
| hover-class | string | navigator-hover | 否 | 指定點(diǎn)擊時(shí)的樣式類,當(dāng)hover-class="none"時(shí),沒有點(diǎn)擊態(tài)效果 | 1.0.0 | ||||||||||||||||||||||
| hover-stop-propagation | boolean | false | 否 | 指定是否阻止本節(jié)點(diǎn)的祖先節(jié)點(diǎn)出現(xiàn)點(diǎn)擊態(tài) | 1.5.0 | ||||||||||||||||||||||
| hover-start-time | number | 50 | 否 | 按住后多久出現(xiàn)點(diǎn)擊態(tài),單位毫秒 | 1.0.0 | ||||||||||||||||||||||
| hover-stay-time | number | 600 | 否 | 手指松開后點(diǎn)擊態(tài)保留時(shí)間,單位毫秒 | 1.0.0 | ||||||||||||||||||||||
| bindsuccess | string | 否 | 當(dāng)target="miniProgram"且open-type="navigate/navigateBack"時(shí)有效時(shí)有效,跳轉(zhuǎn)小程序成功 | 2.0.7 | |||||||||||||||||||||||
| bindfail | string | 否 | 當(dāng)target="miniProgram"且open-type="navigate/navigateBack"時(shí)有效時(shí)有效,跳轉(zhuǎn)小程序失敗 | 2.0.7 | |||||||||||||||||||||||
| bindcomplete | string | 否 | 當(dāng)target="miniProgram"且open-type="navigate/navigateBack"時(shí)有效時(shí)有效,跳轉(zhuǎn)小程序完成 | 2.0.7 | |||||||||||||||||||||||
# 使用限制
- 需要用戶確認(rèn)跳轉(zhuǎn)
從
2.3.0版本開始,在跳轉(zhuǎn)至其他小程序前,將統(tǒng)一增加彈窗,詢問是否跳轉(zhuǎn),用戶確認(rèn)后才可以跳轉(zhuǎn)其他小程序。如果用戶點(diǎn)擊取消,則回調(diào)fail cancel。 - 從2020年4月24日起,跳轉(zhuǎn)其他小程序?qū)⒉辉偈軘?shù)量限制,使用此功能時(shí)請(qǐng)注意遵守運(yùn)營規(guī)范。
# 關(guān)于調(diào)試
- 在開發(fā)者工具上調(diào)用此 API 并不會(huì)真實(shí)的跳轉(zhuǎn)到另外的小程序,但是開發(fā)者工具會(huì)校驗(yàn)本次調(diào)用跳轉(zhuǎn)是否成功。詳情
- 開發(fā)者工具上支持被跳轉(zhuǎn)的小程序處理接收參數(shù)的調(diào)試。詳情
# Bug & Tip
tip:navigator-hover默認(rèn)為{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}, navigator 的子節(jié)點(diǎn)背景色應(yīng)為透明色
# 示例代碼
.navigator-hover {
color:blue;
}
.other-navigator-hover {
color:red;
}
<!-- sample.wxml -->
<view class="btn-area">
<navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳轉(zhuǎn)到新頁面</navigator>
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在當(dāng)前頁打開</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>
<!-- navigator.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 點(diǎn)擊左上角返回回到之前頁面 </view>
<!-- redirect.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 點(diǎn)擊左上角返回回到上級(jí)頁面 </view>
Page({
onLoad: function(options) {
this.setData({
title: options.title
})
}
})