这是我的index.js
:
var routes = require('./config/routes');
ReactDOM.render(routes, document.getElementById('app'));
以下是我的路线:
var routes = (
<Router history={hashHistory}>
<Route path='/' component={Main}>
<IndexRoute component={HomeComponent}/>
<Route path='create' component={CreateComponent} />
<Route path='signUp' component={SignUpComponent} />
</Route>
</Router>
);
最后我的主容器(Main.js
):
var Main = React.createClass({
render: function () {
return (
<div>
<NavBarComponent />
<SecondComponent />
{this.props.children}
<FooterComponent/>
</div>
)
}
});
如您所见,所有页面都有3个常用组件(HeaderComponent,SecondComponent和FooterComponent)。我希望,当特定路线发生变化时(例如'signUp'路线),隐藏SecondComponent。
仅供参考,这是我的反应配置:
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-router": "^3.0.0"