Определяющее действие для redux-first-router
Я намерен использовать redux-first-router для обработки параметра поискового запроса
Просматривая документацию, я интегрировал редуктор, промежуточное программное обеспечение и усилитель, как показано ниже. Если вы заметили, я запускаю действие fetchPage.started
в onPageChange
, При срабатывании fetchPage.started
Действие действительно достигает appReducer, но не до эпоса.
Невозможно определить недостающую часть.
import { combineReducers, applyMiddleware, compose, createStore } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import epic from './epics';
import createHistory from 'history/createBrowserHistory';
import { connectRoutes } from 'redux-first-router';
import queryString from 'query-string';
import { appState, appReducer, fetchPage } from './app/app';
import { LocationState } from 'redux-first-router';
export interface State {
app: appState;
location: LocationState<string, any>;
}
const history = createHistory();
const routesMap = {
fetchPage: '/' // action <-> url path
};
const { reducer: routeReducer, middleware: routeMiddleware, enhancer: routeEnhancer } = connectRoutes(
history,
routesMap,
{
querySerializer: queryString,
onAfterChange: (dispatch: Dispatch<any>, getState: StateGetter<any>) => {
const state = getState();
const query = state.location.query && state.location.query.search;
dispatch(fetchPage.started({index: 0,
pageSize: 10,
sort: [],
query }));
}
});
function createReducer() {
return combineReducers<State>({
app: appReducer,
location: routeReducer
});
}
export default function configureStore(initialState: any) {
const epicMiddleware = createEpicMiddleware();
const middlewares = [epicMiddleware, routeMiddleware];
const enhancers = compose(
routeEnhancer,
applyMiddleware(...middlewares)
);
const store = createStore(createReducer(), initialState, enhancers as any);
epicMiddleware.run(epic);
return store;
}