uniapp中web端微信分享,可用路由hash模式吗
时间: 2023-08-20 15:07:16 浏览: 207
是的,uniapp中web端微信分享可以使用路由hash模式。在uniapp中,路由模式可以配置为hash模式或者history模式。如果你选择使用hash模式,那么微信分享的链接也需要使用hash模式。
具体实现方法如下:
1. 在uniapp的manifest.json文件中配置路由模式为hash模式,如下所示:
```
{
"app": {
"name": "myApp",
"versionName": "1.0.0",
"versionCode": "1",
"description": "",
"author": "",
"homepage": "",
"minSdkVersion": "101",
"router": {
"mode": "hash"
}
}
}
```
2. 在需要分享的页面中获取当前页面的链接,代码如下:
```
let url = window.location.href.split('#')[0] + '#/your-route-name'
```
在这里,我们使用了window.location.href获取了当前页面的链接,并将#后面的部分去掉,然后拼接上你需要分享的路由名称。
3. 调用微信分享API,将链接传入分享参数中,如下所示:
```
wx.onMenuShareTimeline({
title: '分享标题',
link: url,
imgUrl: '分享图标链接'
})
```
在这里,我们将刚刚获取到的链接url传入了分享参数中的link字段中。
以上就是使用uniapp中web端微信分享时使用路由hash模式的方法。
阅读全文
相关推荐

















