How to dynamically change a web page's title?

前端 未结 19 1727
遇见更好的自我
遇见更好的自我 2020-11-22 08:05

I have a webpage that implements a set of tabs each showing different content. The tab clicks do not refresh the page but hide/unhide contents at the client side.

No

19条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 08:39

    for those looking of the npm version of it, there is an entire library for this:

    npm install --save react-document-meta
    


    import React from 'react';
    import DocumentMeta from 'react-document-meta';
    
    class Example extends React.Component {
      render() {
        const meta = {
          title: 'Some Meta Title',
          description: 'I am a description, and I can create multiple tags',
          canonical: 'http://example.com/path/to/page',
          meta: {
            charset: 'utf-8',
            name: {
              keywords: 'react,meta,document,html,tags'
            }
          }
        };
    
        return (
          

    Hello World!

    ); } } React.render(, document.getElementById('root'));

提交回复
热议问题