本文介绍了如何在React中设置文档标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的React应用程序设置文档标题(在浏览器标题栏中)。我尝试过使用 react-document-title (似乎已过期)并设置 document.title 在构造函数和 componentDidMount() - 没有这些解决方案有效。
I would like to set the document title (in the browser title bar) for my React application. I have tried using react-document-title (seems out of date) and setting document.title in the constructor and componentDidMount() - none of these solutions work.
推荐答案import React from 'react' import ReactDOM from 'react-dom' class Doc extends React.Component{ componentDidMount(){ document.title = "dfsdfsdfsd" } render(){ return( <b> test </b> ) } } ReactDOM.render( <Doc />, document.getElementById('container') );
这对我有用。
编辑:如果您使用的是webpack-dev-server,则将内联设置为true
If you're using webpack-dev-server set inline to true
更多推荐
如何在React中设置文档标题?
发布评论