How to update meta tags in React.js?

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

    As create-react-app docs mentioned:

    If you need to dynamically update the page title based on the content, you can use the browser document.title API. For more complex scenarios when you want to change the title from React components, you can use React Helmet, a third party library.

    A simple example:

    function App(){
      document.title = "Home";
      return (
       
    ...
    ) }

提交回复
热议问题