简体   繁体   中英

React page layout using react-router

I have a default layout page here using react router:

Header = require('./components/Header'),
Footer = require('./components/Footer'),


var sampleApp= React.createClass({

getDefaultProps() {
    return {
      title: 'Page One'
    };
},    

render: function (){
    return (
        <div className="app">
            <Header title={this.props.title} />
            <RouteHandler />
            <Footer />
        </div>
    );
},

});

var routes = (
<Route name="app" path="/" handler={sampleApp}>
    <DefaultRoute name="home" handler={HomePage}  />
    <Route name="add-school" handler={AddPage}  />
</Route>
);

Router.run(routes, function(Handler){
var mountNode = document.getElementById('app');
React.render(<Handler /> , mountNode);
});

Am I able to pass the page title into the header component above? Here is one of pages, with the title set in default props.

var HomePage = React.createClass({

mixins: [Router.Navigation],

getDefaultProps() {
    return {
      // set page title here
      title: 'Page Two'
    };
},

getInitialState: function () {
    return {
        tiles: null
    }
},

The page title doesnt show and stays as the default 'page one' in the layout. Can anyone please tell me how I can pass props up to the header component?

您可以使用诸如react-document-title之类的组件来解决该问题。

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