微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-share 参数 'href' 应该代表一个有效的 URL

如何解决react-share 参数 'href' 应该代表一个有效的 URL

我正在使用 react-share 包对我的网页进行社交共享,但在 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}/>

解决方法

如果您使用本地主机,就会发生这种情况,请尝试使用 172.0.0.1 之类的 ip 地址或仅使用您的 ip 地址,您应该得到这样的 url

  let url = '';
  if (typeof window === 'object') {
    url = String(window.location);
    console.log(url);
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。