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.

Cannot read property 'type' of undefined #480

Closed
@gCardinal

Description

@gCardinal

I'm using react-router v3.0.0 and react-router-redux version 4.0.6 (they were both installed with npm with no version specified).

I read the issue #182, but this is not the problem I'm hitting at all. I get this error message every time I use a method from browserHistory to navigate my app (push, goBack, etc.).

Here's how things are configured (there's a few extra things, but I think it's safe to ignore those?):

// index.tsx
import 'polyfills'

import * as React from 'react'

import {render} from 'react-dom'
import {browserHistory} from 'react-router'
import {syncHistoryWithStore} from 'react-router-redux'

import App from 'App'

const createStore = require('redux/store/createStore') as any
const store = createStore.default(browserHistory)
const history = syncHistoryWithStore(browserHistory, store)

render(
    <App store={store} history={history}/>,
    document.getElementById('root')
)
// createStore.ts
import * as createLogger from 'redux-logger'

import {createStore, applyMiddleware, Middleware, compose, StoreEnhancer} from 'redux'
import {routerMiddleware} from 'react-router-redux'
import {composeWithDevTools} from 'redux-devtools-extension'
import {autoRehydrate} from 'redux-persist'

import thunk from 'redux-thunk'
import rootReducer from 'redux/reducers/RootReducer'

export default function (history?: any) {
    return createStore(
        rootReducer,
        null,
        compose(
            composeWithDevTools(
                applyMiddleware(
                    thunk,
                    routerMiddleware(history) as Middleware,
                    createLogger()
                )
            ),
            autoRehydrate()
        ) as StoreEnhancer
    )
}

And then, anywhere I use browserHistory, I'll get the error.

I've been having this problem for a while, but ignored it since it didn't break anything and I thought it was just my configuration that caused that problem. Reading the documentation here and looking at the examples though, I'm not sure of what I'm doing wrong. I'm sure it's something simple, but considering I seem to be configuring everything fine, I'm unsure of what could cause this.

I realize the problem is browserHistory is not dispatching actions the way Redux expects them, but then the documentation does suggest using browserHistory and the examples confirm this.

Is this a bug or am I doing something wrong?

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