Добавление мета-тегов в React. js - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь добавить динамические c мета-теги на каждую страницу. Но все еще не вижу свои метатеги в исходном коде моей страницы. Нужно ли мне что-то помещать в public / index. html ... Я не использую сервер Я пытаюсь добавить мета-теги Dynami c на каждую страницу. Но по-прежнему не вижу свои метатеги в исходном коде моей страницы. Нужно ли мне что-то помещать в public / index. html ... Я не использую сервер. Я пытаюсь добавить метатеги Dynami c на каждую страницу. Но все еще не вижу свои метатеги в исходном коде моей страницы. Нужно ли мне что-то помещать в public / index. html ... Я не использую сервер Пример: Домашняя страница

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.com/" />
                        <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.com/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>

1 Ответ

2 голосов
/ 05 мая 2020

Для этого следует использовать React-шлем , поскольку response-meta-tags устарел.

Как показано в примере документации:

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.com/example" />
            </Helmet>
            ...
        </div>
    );
  }
};
...