我正在使用react共享包来共享我的网页,但是在FacebookShare按钮中显示了一个错误,比如“参数'href‘应该代表一个有效的URL"。
我的Share.js代码是:-
import React from 'react'
import {
FacebookShareButton,
FacebookIcon,
TwitterShareButton,
TwitterIcon,
WhatsappShareButton,
WhatsappIcon,
} from 'react-share'
const ShareButtons = ({title, url}) => {
return(
<div>
<WhatsappShareButton url={url} title={title}className="share-btn">
<WhatsappIcon size={40} round={true}/>
</WhatsappShareButton>
<FacebookShareButton url={url} title={title} className="share-btn">
<FacebookIcon size={40} round={true}/>
</FacebookShareButton>
<TwitterShareButton url={url} title={title} className="share-btn">
<TwitterIcon size={40} round={true} />
</TwitterShareButton>
</div>
)
}
export default ShareButtons在我的页面上:-
<ShareButtons title={this.state.package.title} url={window.location.href}/>发布于 2021-03-27 22:59:12
如果您正在使用localhost,尝试使用像127.0.0.1这样的ip地址或只使用您的ip地址,那么您应该像下面这样获得您的url
let url = '';
if (typeof window === 'object') {
url = String(window.location);
console.log(url);
}发布于 2022-08-24 15:45:56
您说过:尝试使用像172.0.0.1这样的IP地址,我想您的意思是127.0.0.1,将它更改为127.0.0.1对我有用。
https://stackoverflow.com/questions/66097384
复制相似问题