I am trying to redirect to the page after signing out. However, every time when I sign out, it directs the page successfully. However, I still got the error
Cannot read property 'type' of undefined
Further research by "Pause on Caught Exceptions", it is related with react-router-redux.
So the line store.dispatch(push('/signin'))
in the code below causes the issue. If I change to .map(() => ({ type: 'NOT_EXIST' }));
, there will be no issue.
What may cause this? Thanks
actions/auth.action.js
export const signOutSucceedEpic = (action$, store) =>
action$
.ofType(SIGN_OUT_SUCCEED)
.map(() => store.dispatch(push('/signin'))); // <- this line causes the issue
actions/index.js
import { combineEpics } from 'redux-observable';
export default combineEpics(
// ...
signOutSucceedEpic
);
index.js
import { Provider } from 'react-redux';
import { Route } from 'react-router-dom';
import { ConnectedRouter, routerMiddleware, push } from 'react-router-redux';
import createHistory from 'history/createBrowserHistory';
import rootEpic from './actions/index';
const history = createHistory();
const routeMiddleware = routerMiddleware(history);
const epicMiddleware = createEpicMiddleware(rootEpic);
export const store = createStore(
rootReducer,
persistedState,
composeWithDevTools(
applyMiddleware(
epicMiddleware,
routeMiddleware
)
)
);
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<Route path="/signin" component={SignIn} />
<Route exact path="/" component={Home} />
</div>
</ConnectedRouter>
</Provider>,
document.getElementById('root')
);