The application has registered and unregistered users. Accordingly, for those and for others there will be different heders on the site (heders are in separate files and exported to the site pages). Using the onEnter hook in the reactor's root, I implement a method for checking the presence of a token in the current session with the user. If there is a token to be present, the user can go to certain root, if not, then using the replace redirect on the page with the login form. Everything works, but there is one snag - the header. You can implement a check in each component and, depending on it, send a guest, or custom header, but I do not think this is a good solution. I think the best way would be to check if the user is logged in or not and to throw one or another header into the page at the level of the router. Unfortunately, I did not find a suitable solution on the net. Please tell me how to do better in this situation?
Code of the router and onEnter (Now I have made 2 main pages and specified the necessary headers in them. Accordingly, if it turns out to throw the necessary header, there will be one main page):
const App = React.createClass({ render: function() { return ( <div className="content"> <div className="app-container"> {this.props.children} </div> </div> ) } }); function authCheck(nextState,replace) { const token = window.localStorage.getItem(config.token); if (token != undefined) { } else { replace('/login'); } } render((<Router history={hashHistory}> <Route path="/" component={App}> <IndexRoute component={MainPageGuest}/> <Route path="dash" component={MainPageUser} onEnter={authCheck}/> <Route path="user" component={UserPage} onEnter={authCheck}/> </Route> </Router> ), document.getElementById('application'));