Been at this all weekend. Upon refresh of the page, React Router keeps routing to the /login page first, then to the homepage "/".
ReactDOM.render(
<Provider store={store}>
<Router>
<Switch>
<Route path="/login" component={Login} />
<AuthenticatedComponent>
<Header />
<Route path="/" component={App} exact />
</AuthenticatedComponent>
</Switch>
</Router>
</Provider>,
document.getElementById("root")
);
I've tried moving around the Routes but that doesn't work - no errors, it just does the same thing. One thing I'm doing is saying. "If user is logged in (no null), immediately route them to the home page "/". This is being done in the { Login } component and written below:
componentWillReceiveProps(props) {
if(props.user !== null) {
props.history.push('/')
}
}
This works like a charm. The problem is, whenever I refresh my browser, the url immediately goes to /login, then to "/", which is home. I added the AuthenticatedComponent wrapper as a last resort test. I have written in this component the following:
componentWillMount(){
if( this.props.user !== null) {
this.props.history.push('/')
} else {
this.props.history.push('/login')
}
}
I'm not receiving any errors - The functionality is just off a little