eclipsis eclipsis - 3 months ago 74
React JSX Question

React-Router: Print page title in component?

I'm struggling with how to print the current page title in React/React-Router. What I currently have:

Routes:

<Route path='parent' component={Parent}>
<Route path='child1' component={Child1}/>
<Route path='child2' component={Child2}/>
<Route path='child3' component={Child3}/>


Component:

const Vehicle = React.createClass({
render() {
return (
<h4 className="sub-title col-12">{this.state.title}</h4>
);
}
});

Answer

If I correctly understand you, you can get page title using document.title:

const Vehicle = React.createClass({
    render() {
        return (
            <h4 className="sub-title col-12">{document.title}</h4>
        );
    }
});