Assume the following Route setup:
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/">
<Route component={Layout} onEnter={checkIndexAuthorization(store)}>
<IndexRoute component={Home} />
<Route path="/home" component={Home} />
</Route>
<Route component={AuthLayout} onEnter={checkLoginAuthorization(store)}>
<Route path="/login" component={Login} />
</Route>
</Route>
</Router>
</Provider>,
document.getElementById('root'),
)
As you can see, there are two main layouts, the normal Layout and the login page AuthLayout. The normal layout is used for the app proper.
Below, you can see the Layout component file:
//========================================
// IMPORTS
//========================================
import React, { PropTypes } from 'react';
//========================================
// COMPONENT
//========================================
const Layout = props => (
<main className="app">
<header>
{props.sectionTitle}
</header>
<section>
{props.children}
</section>
<footer>
</footer>
</main>
)
Layout.propTypes = {
children: PropTypes.node,
sectionTitle: PropTypes.string // <-- not being set anywhere currently
}
//========================================
// EXPORTS
//========================================
export default Layout;
Now, that layout has a title section at the top, that needs to display text based on where in the app we are.
As I'm new to React JS, I didn't want to just look up 'how to pass props from router' or similar - rather, I'm interested in what the correct way to do this might be. The 'React way', if you will. Whether that involves passing props directly from the route, or changing a global state of some kind to affect the title, or whatever the 'correct' way of handling this scenario would be.
EDIT: I should mention that I'm using React JS v. 15.6.1, and react-router v. 3.0.5.