eclipsis
eclipsis

Reputation: 1550

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>
        );
    }
});

Upvotes: 0

Views: 2635

Answers (1)

1ven
1ven

Reputation: 7026

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>
        );
    }
});

Upvotes: 2

Related Questions