How to update meta tags in React.js?

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

    You cand also give the page title and meta tags description in the following way.

    place a meta tag of description in your index.html file like this.

    
    
    
    Dynamic Page title here
    

    in your .js files or .jsx files below the render() method write the page title and meta description for the page like this .

    render()
    {
    document.title ="Welcome | here is your page title to display"; 
    document.getElementsByTagName("META")[2].content="Your description about the page or site here to set dynamically";
    
    return(
        
    Page content
    ); }

提交回复
热议问题