外部h5網頁無法直接跳轉到小程序,因此需要把h5內嵌到小程序的web-view中。只有內嵌的H5才能跳回小程序
官方文檔:https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
web-view
承載網頁的容器。會自動鋪滿整個小程序頁面,個人類型的小程序暫不支持使用。
一、小程序跳轉h5
<!-- wxml --> <web-view src="https://xxx.com/test.html?id=123"></web-view>
網頁放至屬性src即可實現自動跳轉,需在微信后台設置為白名單
二、h5跳轉至小程序
1、將h5內嵌到小程序中,相當於小程序跳轉至h5
<view> <web-view src="https://xxx.com/test.html"></web-view> </view>
//h5 <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script> <script> wx.miniProgram.navigateTo({url: '/pages/index/index?shareId=123'}) </script>
這樣即可實現從h5跳到小程序(指定頁面)
ts:
小程序代碼-接收url拼接參數
if(options.shareId){
let shareId = options.shareId /*獲取參數*/
that.setData({
shareId: shareId,
})
}