在项目根目录下app.js设置:
App({
onLaunch: function() { //启动小程序执行方法
this.overShare()
},
//重写分享方法
overShare() {
//监听路由切换
//间接实现全局设置分享内容
wx.onAppRoute(function(res) {
//获取加载的页面
let pages = getCurrentPages(),
//获取当前页面的对象
view = pages[pages.length - 1],
data;
if (view) {
data = view.data;
console.log('是否重写分享方法', data.isOverShare);
if (!data.isOverShare) {
data.isOverShare = true;
view.onShareAppMessage = function() {
//你的分享配置
return {
title: '送你一份小惊喜,请查收!',
path: '/pages/index/index',
imageUrl:''
};
}
}
}
})
},
})