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
, andstyle
tags.
支持所有有效的头部标签
- Supports attributes for
body
,html
andtitle
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
使用
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://mysite.com/example" />
</Helmet>
...
</div>
);
}
};