Define the route /authentication/logout :
import React from 'react'; import { Route, IndexRoute } from 'react-router'; import { HomeView, LoginView, LogoutView } from './../views'; export default <Route path='/'> <IndexRoute component={HomeView} /> <Route path='/authentication/logout'component={LogoutView} /> <Route path='/authentication/login' component={LoginView} /> </Route>;
Create a LogoutView that sends the action to componentWillMount :
import React from 'react'; import { authenticationActionCreator } from './../actionCreators'; import { connect } from 'react-redux'; import { pushPath } from 'redux-simple-router'; let LogoutView; LogoutView = class extends React.Component { componentWillMount () { this.props.dispatch(authenticationActionCreator.logout()); this.props.dispatch(pushPath('/')); } render () { return null; } }; export default connect()(LogoutView);
The componentWillMount callback sends two actions:
- To destroy a user session.
- To redirect the user to
IndexRoute .
this.props.dispatch(authenticationActionCreator.logout()); this.props.dispatch(pushPath('/'));
Gajus
source share