微信小程序分享页面如何返回首页

发布时间:2025-04-04 点击:7
做小程序开发发现,页面分享出去后,用户通过分享进去的页面很难找到返首页的情况。(微信官方操作是点击右上角三个点,在手机下方显示返回首页)。民间很多方案是自己在页面加个悬浮home标注。
今天我分享另外一种方法。代码如下:
<!--index.wxml-->
<view class=container>
<text>我是首页</text>
<button bindtap='gologs'>go logspage</button>
</view>
const app = getapp()
page({
data: {
motto: 'hello world',
userinfo: {},
hasuserinfo: false,
caniuse: wx.caniuse('button.open-type.getuserinfo')
},
//事件处理函数
gologs: function() {
wx.navigateto({
url: '/pages/logs/logs'
})
},
onload: function (options) {
console.log(options)
if (options.share_query){
wx.showloading({
title: '我是从分享页面进入的',
})
settimeout(function () {
wx.hideloading()
wx.navigateto({
url: '/pages/logs/logs',
})
}, 2000)
}
}
})
<!--logs.wxml-->
<view class=container log-list>
<block wx:for={{logs}} wx:for-item=log>
<text class=log-item>{{index + 1}}. {{log}}</text>
</block>
</view>
const app = getapp()
page({
data: {
motto: 'hello world',
userinfo: {},
hasuserinfo: false,
caniuse: wx.caniuse('button.open-type.getuserinfo')
},
//事件处理函数
gologs: function() {
wx.navigateto({
url: '/pages/logs/logs'
})
},
onload: function (options) {
console.log(options)
//判断是否分享进入
if (options.share_query){
wx.showloading({
title: '我是从分享页面进入的',
})
settimeout(function () {
wx.hideloading()
wx.navigateto({
url: '/pages/logs/logs',
})
}, 2000)
}
}
})

wap开发:网站如何移动化
深圳网站建设的价格为什么不一样?
浅谈影响百度排名的因素有那些
重庆到牡丹江物流专线
中山到玉环物流专线
武汉到阜新物流专线
企业网站常见问题有哪
如何做大数据营销