admin 管理员组文章数量: 1086019
I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server Example: Home page
import {Helmet} from 'react-helmet';
export default class Home extends Component {
render() {
return (
<div>
<head>
<Helmet>
<meta charSet="utf-8" />
<title>Home</title>
<link rel="canonical" href="/" />
<meta name="description" content="Some description here" />
</Helmet>
</head>
I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server I'm trying to add dynamic meta-tags on every single page. But still can't see my meta-tags on my page source code. Do I need to put something in public/index.html... I'm not using server Example: Home page
import {Helmet} from 'react-helmet';
export default class Home extends Component {
render() {
return (
<div>
<head>
<Helmet>
<meta charSet="utf-8" />
<title>Home</title>
<link rel="canonical" href="https://example./" />
<meta name="description" content="Some description here" />
</Helmet>
</head>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google./web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Website</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Share
Improve this question
edited May 5, 2020 at 14:23
Selda
asked May 5, 2020 at 13:27
SeldaSelda
451 gold badge1 silver badge8 bronze badges
1 Answer
Reset to default 5You should use React-helmet for this as react-meta-tags is outdated.
As the documentation example shows:
import React from "react";
import {Helmet} from "react-helmet";
class Application extends React.Component {
render () {
return (
<div className="application">
<Helmet>
<meta charSet="utf-8" />
<title>My Title</title>
<link rel="canonical" href="http://example./example" />
</Helmet>
...
</div>
);
}
};
本文标签: javascriptAdding meta tags on ReactjsStack Overflow
版权声明:本文标题:javascript - Adding meta tags on React.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744017994a2519278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论