Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Getting 'Uncaught TypeError: Cannot read property 'type' of undefined' when using with react-router 2.x #182

Closed
@trattles

Description

@trattles

I am getting an error when trying to set up redux simple router.

I'm setting up redux simple router like so (excuse messy imports from various features). Where am I going wrong?

"redux-simple-router": "^2.0.1",
"react-router": "2.0.0-rc4",

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, browserHistory } from 'react-router';

import {createStore, applyMiddleware, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import reducers from './../common/Reducers/index.js';
import thunkMiddleware from 'redux-thunk';
import { syncHistory, routeReducer } from 'redux-simple-router';

const reducer = combineReducers(Object.assign({}, reducers, {routing: routeReducer }));
const initialState = window.__INITIAL_STATE__;
const simpleRouter = syncHistory(browserHistory);
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, simpleRouter)(createStore);

const store = createStoreWithMiddleware(reducer(initialState));
simpleRouter.syncHistoryToStore(store);

import routeConfig from './../common/routes/Routes.js';
import Radium, {Style, StyleRoot} from 'radium';
import Normalize from './../common/styles/Normalize.js';



ReactDOM.render(
    <Provider store={store}>
        <StyleRoot>
        <Router routes={routeConfig} history={browserHistory}>
        </Router>
        <Style rules={Normalize} />
        </StyleRoot>
    </Provider>
, document.getElementById('app-mount'));

This results in the following error:

Uncaught TypeError: Cannot read property 'type' of undefined

Here is the relevant source of the error - the "var type = _ref.type;"

// Reducer

    var initialState = {
      location: undefined
    };

    function routeReducer() {
      var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0];
      var _ref = arguments[1];
      var type = _ref.type;
      var location = _ref.location;

      if (type !== UPDATE_LOCATION) {
        return state;
      }

      return { location: location };
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions