Why react Router is not reactive like iron Router?


#1

In this code; I except that the router go to the home page automatically when the user is log in

Meteor.startup(() => {

	const  requireAuth = function requireAuth(nextState, replace) {
    if (!Meteor.user()) {
        replace({
            pathname: '/login',
            state: { nextPathname: nextState.location.pathname }
        })
    }
}

const  requireNotAuthed = function requireNotAuthed(nextState, replace) {
    if (Meteor.user()) {
        replace({
            pathname: '/',
        })
    }
}

 render(
 	<Router history = {browserHistory}>
 	      <Route path="/" component={ Navigation } onChange={requireAuth}>
	 	      <IndexRoute component={ App } onEnter={requireAuth} />
		      <Route path="/one" component={ One } onEnter={requireAuth} />
		      <Route path="/two" component={ Two } onEnter={requireAuth} />
		      <Route path="/login" component={Login} />
		      <Route path="*" component={ Not } onEnter={requireAuth} />
		   </Route>
 	</Router>, 


 	document.getElementById('app'));
}); 

unfortunatly, it does not and the user should on Home icon to go to it;

Did I miss something on my code ??


#2

Try using Tracker.autorun()

Your if-clauses currently get executed exactly once upon startup.


#3

Thank’s, it works great; that said, why I should update the page to render Home page when the user log in ?