Using "react-router-dom": "^4.1.2", "react-router-redux": "^5.0.0-alpha.6" I get as per title "Uncaught TypeError: Cannot read property 'type' of undefined React Router Redux" in console.log() the moment after the redirect is done. Screenshots show it's not a problem with the action observable containing the payload data. Payload contains form data (values) and history object. I managed to send them and then capture them by means of a recursive function that uses mergeMap instead of ES6 map since I am dealing with Observables. link to the repo
import * as ActionTypes from "../ActionTypes";
import { createPostFulfilled, fetchPosts, fetchPostsFulfilled, fetchPostsWithIdFulfilled, changeRoute } from "../actions";
import {store, history} from "../configureStore";
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/combineLatest";
import "rxjs/add/operator/debounceTime";
import { concat as concat$ } from "rxjs/observable/concat";
import { from as from$ } from "rxjs/observable/from";
import { of as of$ } from "rxjs/observable/of";
import "rxjs/add/operator/map";
import "rxjs/add/operator/mergeMap";
import "rxjs/add/operator/startWith";
import "rxjs/add/operator/filter";
import "rxjs/add/operator/switchMap";
import "rxjs/add/operator/concatMap";
import "rxjs/add/operator/catch";
import "rxjs/add/observable/dom/ajax";
import {push} from "react-router-redux";
const ROOT_URL = "http://reduxblog.herokuapp.com/api";
const API_KEY = "key=davide123";
export const fetchPostsEpic = (action$) => {
return action$.filter((action$)=> action$.type === ActionTypes.FETCH_POSTS)
.mergeMap(action$ => {
return Observable.ajax.getJSON(`${ROOT_URL}/posts/?${API_KEY}`)
.map(response => fetchPostsFulfilled(response), (err) => {console.log(err);});
});
};
export const fetchPostsWithIdEpic = (action$) => {
return action$.filter((action$)=> action$.type === ActionTypes.FETCH_POSTS_WITH_ID)
.mergeMap(action$ => {
return Observable.ajax.getJSON(`${ROOT_URL}/posts/?${action$.payload}&${API_KEY}`)
.map(response => fetchPostsWithIdFulfilled(response), (err) => {console.log(err);});
});
};
export const createPostEpic = (action$) => {
const actionVectorizer = ((action$) => {
if (action$)
return action$.isArray() ? [].concat(...action$.mergeMap(x => actionVectorizer(x))) : action$;
})();
return action$.filter((action$)=> action$.type === ActionTypes.CREATE_POST)
.mergeMap(action$ => {
console.log("action$ is...");
console.log(action$);
let { values, history } = action$.payload;
return Observable.ajax.post(`${ROOT_URL}/posts/?${API_KEY}`, values)
.map(
(data) => {
if (data.status === 201) {
console.log("Success status", data.status);
history.push("/");
// return createPostFulfilled(data.status);
}
else {console.log("Server error is", data.status);}
},
(err) => {console.log(err);}
);
});
};