简体   繁体   中英

How change the title of a page before it loads JSX

I want change the title of a class, and I achieve it with document.title = "flayers" but I put this code in the constructor,then firt I have a default title and change it then when I refer to the url, show the old title.

first I have this title

在此处输入图片说明

next I change for this 在此处输入图片说明

and when I refer to url : 在此处输入图片说明

I don't know if I explain :D

Are you familiar with React-Router? You can change the name of the title page by placing a componentDidMount in the desired component, which will fire when the component is loaded. Then, you'll simply use document.title to target and change the page's title.

Here's an example , which I took from issue ticket #49 in the React-Router Github repository:

var Handler = React.createClass({
componentDidMount: function() {
document.title = "Amazing Page";
}
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM