微信小程序内嵌h5 分享子页面点击进入后是主页面解决办法

javascript 复制代码
<web-view src='{{src}}'></web-view>
javascript 复制代码
src: `https://XXXXXX,
javascript 复制代码
/**
 * 生命周期函数--监听页面加载
*/
onLoad(options) {
  this.srcFun(options)
},
javascript 复制代码
srcFun(options){
	//当有子页面id时 更改内嵌页链接
    if (options.urlPathNew) { 
      let url=`https://XXX/caseOrder?classicId=${options.urlPathNew}`
      this.setData({
        src:url
      })
    }
},

通过子页面特定的id有无进行判断,可根据项目自行修改

javascript 复制代码
/**
   * 用户点击右上角分享
   */
  onShareAppMessage(options) {
    const h5Url = options.webViewUrl; //当前页面h5的链接
    // 使用正则表达式提取 classicId 的值
    const matchResult = h5Url.match(/classicId=(\d+)/); 
    // 判断是否匹配成功
    let srcPath='/pages/caseH5/case'
    if (matchResult && matchResult.length > 1) {
      let classicIdValue = matchResult[1];
      srcPath=`/pages/caseH5/case?urlPathNew=${classicIdValue}`
    } else {
      console.log("未找到 classicId");
    }
    return{
      title: "分享成功",  //分享的标题
      path: srcPath, //分享的路径
      imageUrl:'/assets/share.png' //分享的封面图片
    }
  }
相关推荐
衍生星球16 小时前
SpringBoot3 + Vue3 + 微信小程序如何学习,以及学哪些技术,组件
sql·微信小程序·uni-app·vue·springboot
weixin_4514315617 小时前
落地到一个真实项目里——一个 AI驱动的冰箱食材管理小程序
人工智能·ai·小程序
hnxaoli1 天前
统信小程序(十六)xls转xlsx
开发语言·python·小程序
卓怡学长1 天前
w272基于springboot便民医疗服务小程序
java·spring boot·spring·小程序·intellij-idea
新华财经频道1 天前
2026微信小程序搭建平台实测测评,优缺点解析
微信小程序·小程序
kidding7232 天前
旋转大转盘小程序
前端·css·微信小程序·小程序·前端框架
码农客栈2 天前
小程序学习(二十九)之项目打包
小程序
凡科建站2 天前
2026年艺术类教育小程序开发平台有哪些?艺术类教育小程序开发平台推荐
小程序
LT10157974443 天前
2026年在线兼容性测试工具推荐|零部署网页 / APP / 小程序实测对比
测试工具·小程序
码农客栈3 天前
小程序学习(二十八)之“订单列表”
小程序