I'm trying to redirect user to '/' route in my redux action. But I can see that the route in the browser is changing but component does not render (it stays at the same view).
My action looks like that:
import history from '../../history';
export const logoutUser = () => dispatch => {
api.logout();
// redirect
history.push('/');
dispatch({ type: TYPES.LOGOUT_USER });
};
My component with routes looks like that:
import React, { Component, Fragment } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import history from './history';
import { Landing, AnotherComponent } from './views';
class App extends Component {
render() {
return (
<Fragment>
<Router history={history}>
<div className="main-container">
<Route exact path="/" component={Landing} />
<Route path="/another_route" component={AnotherComponent} />
</div>
</Router>
</Fragment>
);
}
}
export default App;
And history.js file:
import createHistory from 'history/createBrowserHistory';
export default createHistory();
Thanks for helping!
<Redirect />component fromreact-router-dombased on whatever store property you use to track authenticated status.