2017-01-06 2 views
0

Вот мой index.js:ReactJS - Получить информацию обратно к основному маршруту

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, SecondCom ponent и FooterComponent). Я хотел бы, когда определенный маршрут изменится (скажем, например, маршрут signUp), чтобы скрыть SecondComponent.

FYI, вот мой реагировать конфигурации:

"react": "^15.4.1", 
"react-dom": "^15.4.1", 
"react-router": "^3.0.0" 
+1

Поместите условный оператор в 'Main', который смотрит на' window.location.href'. И только визуализируйте 'SecondComponent', если условное прошло. – lux

ответ

Смежные вопросы