我正在开发一个反应项目。我在index.html中给出了默认的标题标记和元标记。我试图更新每一页的标题和元标签通过道具使用反应头盔。标题标记会被更新,但只更新几秒钟。每当我在5-10秒之后更改浏览器选项卡时,标题就会恢复到默认值。至于其他元标记,这些标记根本不覆盖。
index.html
<head>
<title>Content...</title>
<meta name="description" content="description/>
</head>我的组件
<Helmet>
<title>{this.state.meta_title}</title>
<meta name="description" content={this.state.meta_description}/>
</Helmet>我试过用data-react-helmet="true".
<meta name="description" content={this.state.meta_description} data-react-helmet="true"/>但没什么用。我试图从过去的两天开始解决这个问题,但没有运气。如果有人能帮我,请帮帮我。
更新
我找到解决办法了。我在页面里打电话给头盔。当我在App.js文件中调用组件时,它就开始工作了。标题问题是固定的,但元标记没有更新。新的元标签得到添加在头部底部。
发布于 2022-06-20 12:15:08
就像@TomFinney说的:只是在index.html中的标签中添加 data-react-helmet="true"。从反应头盔 更新这些元素时,通过属性标识它们。开始。
index.html
<title>From Index</title> <!-- title is an exception and does not require it -->
<meta name="description" content="From Index" data-react-helmet="true" />App.jsx
<Helmet>
<title>From Helmet</title>
<meta name="description" content="From Helmet" />
</Helmet>作品:https://e8bnj8.csb.app/ \ https://codesandbox.io/s/tender-gould-e8bnj8?file=/src/App.js
您可以通过禁用浏览器中的javascript来测试它。
https://stackoverflow.com/questions/60547576
复制相似问题