IndexRoute未显示在路径中

时间:2016-09-26 13:37:41

标签: reactjs

我是React新手,我创建了一个基本路由应用程序,其中包含路径和索引路径作为子项。 routes.js文件如下:

var React = require('react');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var browserHistory = ReactRouter.browserHistory;
var IndexRoute = ReactRouter.IndexRoute;
var ApplicationHeader = require('../new_components/ApplicationHeader');
var MainPage = require('../new_components/MainPage');

var routes = (
 <Router history={browserHistory}>
<Route path="/" component={ApplicationHeader}>
  <IndexRoute component={MainPage}/>
</Route>
</Router>
);

module.exports = routes;

ApplicationHeader.js文件如下:

var React = require('react');

var ApplicationHeader = React.createClass({

    render: function () {
      return (<header>
        <div>Application Header</div>
      </header>)
    }
  }
)

module.exports = ApplicationHeader;

MainPage.js文件如下:

var React = require('react');

var MainPage = React.createClass({

  render: function(){
    return(<div>Main Page</div>);
  }
})

module.exports = MainPage;

但是,在运行应用程序时,只有应用程序标题&#39;元素显示。我确实应该显示主页面元素,但它不会。有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:3)

在ApplicationHeader组件中,您还需要渲染子项

=SUM(H3:H15*--(MOD(ROW(H3:H15),3)=2))