neilff / redux-ui-router

ngRedux bindings for Angular UI Router
MIT License
143 stars 48 forks source link

Getting ` Cannot convert undefined or null to object` when adding router to combineReducers #72

Closed xlozinguez closed 7 years ago

xlozinguez commented 7 years ago

Hey there,

I'm getting the following when adding the router to my redux store:

angular.js?3437:13920TypeError: Cannot convert undefined or null to object
    at routerStateReducer (eval at <anonymous> (bundle.js?80e2857…:3158), <anonymous>:32:16)
    at combination (eval at <anonymous> (bundle.js?80e2857…:3002), <anonymous>:132:29)
    at i (<anonymous>:1:14096)
    at u (<anonymous>:1:14382)
    at <anonymous>:1:17277
    at Object.dispatch (eval at <anonymous> (bundle.js?80e2857…:2948), <anonymous>:179:22)
    at dispatch (<anonymous>:1:17719)
    at eval (eval at <anonymous> (bundle.js?80e2857…:3134), <anonymous>:9:31)
    at eval (eval at <anonymous> (bundle.js?80e2857…:5361), <anonymous>:89:29)
    at eval (eval at <anonymous> (bundle.js?80e2857…:5409), <anonymous>:62:22)

For some context, it was working fine and then I hooked up redux-observables which leverages its own middleware

Note that the router params is correctly added to the store but the state is not correctly handled (no data seems to be stored).

You can test in the context of my demo app.

xlozinguez commented 7 years ago

Update: Not sure if that's the prettiest way but I ended up creating an epic around the @@reduxUiRouter/$stateChangeStart action to handle fetching the page resources: this way ...

Unfortunately, since the $stateChangeSuccessaction doesn't provide the corresponding state params, I had to use the $stateChangeStart... If someone had to deal with the same sort of thing, I'm all hear :)

housseindjirdeh commented 7 years ago

Was seeing the same issue but then realized that I forgot to include thunk and the appropriate middleware when creating the store, that solved the problem :)

$ngReduxProvider.createStoreWith(
    reducer,
    ['ngUiRouterMiddleware', thunk, Logger]
  );
hally9k commented 7 years ago

@xlozinguez did adding the thunk middleware fix this for you aswell?

hally9k commented 7 years ago

@xlozinguez - closing but feel free to reopen if you still have this issue.