You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目启动本地服务器触发react-helmet报错,附代码寻求排查解决

问题原因

你在react-helmet的<Helmet>组件内部额外嵌套了一层<head>标签,违反了组件的使用规则。Helmet组件本身的功能就是将其内部包裹的title、meta等头部标签自动注入到页面的原生<head>节点中,不需要手动在组件内部再次声明<head>标签。

修复方案

删除<Helmet>内部包裹的多余<head>、</head>标签,直接将头部标签放在<Helmet>下即可,修改后的代码片段如下:

<Helmet>
    <title> Home | BradGradGraphics</title>
    <meta property="og:description" content="Freelancing service that offers graphic design, illustration, and some small web design work digitally" />
    <meta property="og:url"   content="https://bradgrad.graphics" />
    <meta property="og:type"  content="website" />
    <meta property="og:title" content="BradGradGraphics" />
    <meta property="og:image" content="../images/SplashPgConc.png" />
</Helmet>

额外优化提示

你当前og:image使用的相对路径在React打包后可能无法被正确识别,可以将图片导入后使用变量赋值给content属性,或把图片放到项目public目录下使用绝对路径引用,避免分享时图片加载失败。

内容的提问来源于stack exchange,提问作者Brad G.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 12:27:04