How to update meta tags in React.js?

后端 未结 9 885
清酒与你
清酒与你 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:58

    You almost definitely want to use:

    React Helmet

    In contrast to react-meta-tags it can nest s and so you can define your meta tags deep within your app - like </code>s that should override each other. And in contrast to <code>react-document-meta</code> you can define things using jsx (and nest things).</p> <p>This seems to be the solution that the community almost exclusively uses - 600,000 weekly downloads vs the 6,000 given in other solutions. "Helmet takes plain HTML tags and outputs plain HTML tags. It's dead simple, and React beginner friendly." - and has support for server-side rendering.</p> <p>Here's an example, adapted from the front page:</p> <pre><code><Parent> I'm a parent <Helmet> <title>My Title I'm a child Nested Title

    outputs:

    
        Nested Title
        
    
    
        I'm a parent
        
            I'm a child
        
    
    

提交回复
热议问题