react-helmet
这个可复用的react组件将管理你在文档头的所以更改。
This reusable React component will manage all of your changes to the document head.

特性

  • Supports all valid head tags: title, base, meta, link, script, noscript, and style tags.

支持所有有效的头部标签

  • Supports attributes for body, html and title tags.

支持body、html、title标签

  • Supports server-side rendering.

支持服务器端渲染

  • Nested components override duplicate head changes.

嵌套组件覆盖重复的头更改

  • Duplicate head changes are preserved when specified in the same component (support for tags like “apple-touch-icon”).

当在同一组件中指定时,重复的头更改将被保留(支持“apple-touch-icon”之类的标记)

  • Callback for tracking DOM changes.

跟踪DOM更改的回调

安装

Yarn:
yarn add react-helmet
npm:
npm install --save react-helmet

使用

  1. import React from "react";
  2. import {Helmet} from "react-helmet";
  3. class Application extends React.Component {
  4. render () {
  5. return (
  6. <div className="application">
  7. <Helmet>
  8. <meta charSet="utf-8" />
  9. <title>My Title</title>
  10. <link rel="canonical" href="http://mysite.com/example" />
  11. </Helmet>
  12. ...
  13. </div>
  14. );
  15. }
  16. };