【发布时间】:2018-01-05 20:55:57
【问题描述】:
我在退出后尝试重定向到该页面。但是,每次我退出时,它都会成功引导页面。但是,我仍然收到错误
无法读取未定义的属性“类型”
“Pause on Caught Exceptions”进一步研究,与react-router-redux有关。
所以下面代码中的store.dispatch(push('/signin')) 行会导致问题。换成.map(() => ({ type: 'NOT_EXIST' }));就没有问题了。
什么可能导致这种情况?谢谢
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')
);
【问题讨论】:
-
我想你忘了指定类型,这样写:
store.dispatch({type: 'abc', data: push('/signin')});检查DOC 示例。
标签: javascript reactjs react-redux react-router-redux redux-observable