简体   繁体   English

加载JSX之前如何更改页面标题

[英]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. 我想更改一个类的标题,并通过document.title =“ flayers”实现它,但是我将这段代码放在了构造函数中,然后我设置了默认标题,然后在引用url时进行了更改,显示旧标题。

first I have this title 首先我有这个标题

在此处输入图片说明

next I change for this 接下来我换这个 在此处输入图片说明

and when I refer to url : 当我提到url时: 在此处输入图片说明

I don't know if I explain :D 我不知道我是否解释:D

Are you familiar with React-Router? 您熟悉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. 您可以通过将componentDidMount放置在所需的组件中来更改标题页的名称,该组件会在加载组件时触发。 Then, you'll simply use document.title to target and change the page's title. 然后,您只需使用document.title来定位并更改页面的标题。

Here's an example , which I took from issue ticket #49 in the React-Router Github repository: 这是一个示例 ,我是从React-Router Github存储库中的第49个发行凭单中获取的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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