React-Router: 在组件中打印页面标题?
React-Router: Print page title in component?
我正在为如何在 React/React-Router 中打印当前页面标题而苦恼。我目前拥有的:
路线:
<Route path='parent' component={Parent}>
<Route path='child1' component={Child1}/>
<Route path='child2' component={Child2}/>
<Route path='child3' component={Child3}/>
组件:
const Vehicle = React.createClass({
render() {
return (
<h4 className="sub-title col-12">{this.state.title}</h4>
);
}
});
如果我没理解错的话,你可以使用document.title
:
获取页面标题
const Vehicle = React.createClass({
render() {
return (
<h4 className="sub-title col-12">{document.title}</h4>
);
}
});
我正在为如何在 React/React-Router 中打印当前页面标题而苦恼。我目前拥有的:
路线:
<Route path='parent' component={Parent}>
<Route path='child1' component={Child1}/>
<Route path='child2' component={Child2}/>
<Route path='child3' component={Child3}/>
组件:
const Vehicle = React.createClass({
render() {
return (
<h4 className="sub-title col-12">{this.state.title}</h4>
);
}
});
如果我没理解错的话,你可以使用document.title
:
const Vehicle = React.createClass({
render() {
return (
<h4 className="sub-title col-12">{document.title}</h4>
);
}
});