How to update meta tags in React.js?

后端 未结 9 924
清酒与你
清酒与你 2020-12-28 12:05

I was working on a single page application in react.js, so what is the best way to update meta tags on page transitions or browser back/forward?

9条回答
  •  我在风中等你
    2020-12-28 12:48

    You can use react-meta-tags. It allows you to write title and other meta tags in a declarative way and in normal jsx format, which will be moved to head (Check server usage on the doc).

    import React from 'react';
    import MetaTags from 'react-meta-tags';
    
    class Component1 extends React.Component {
      render() {
        return (
            
    Page 1
    Some Content
    ) } }

    You may also like to check react-helmet if you have an advanced use case.

提交回复
热议问题