TypeError: Cannot read property 'pathname' of undefined
See original GitHub issueLooks like this is a regression of https://github.com/supasate/connected-react-router/issues/54, and potentially related to https://github.com/supasate/connected-react-router/issues/183
But I am getting a TypeError: Cannot read property 'pathname' of undefined
error when simply following the docs.
// reducers.ts
import { combineReducers } from 'redux'
import { connectRouter } from 'connected-react-router'
export const createRootReducer = (history) => combineReducers({
routing: connectRouter(history)
})
// store.ts
import { createBrowserHistory } from 'history'
import { createStore, applyMiddleware } from 'redux'
import { routerMiddleware } from 'connected-react-router'
import { createRootReducer } from './reducers'
export const history = createBrowserHistory()
export const store = createStore(
createRootReducer(history),
applyMiddleware(routerMiddleware(history))
)
// app.tsx
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { Route } from 'react-router-dom'
import { ConnectedRouter } from 'connected-react-router'
import { store, history } from './store'
const App = () => (
<Provider store={store}>
<ConnectedRouter history={history}>
<React.Fragment>
<Route exact path="/" component={HomePage} />
<Route path="/about" component={AboutPage} />
<Route path="/topics" component={TopicsPage} />
</React.Fragment>
</ConnectedRouter>
</Provider>
)
ReactDOM.render(<App />, document.getElementById('app'))
// versions
"react": "^16.6.0"
"react-dom": "^16.6.0"
"react-redux": "^5.1.0"
"react-router-dom": "^4.3.1"
"redux": "^4.0.1"
"connected-react-router": "^5.0.1"
"history": "^4.7.2"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:32
- Comments:30 (3 by maintainers)
Top Results From Across the Web
React Router: Cannot read property 'pathname' of undefined
I've just started learning React and got stuck at this error. Uncaught TypeError: Cannot read property ...
Read more >Cannot read properties of undefined (reading 'pathname')
The error "Cannot read properties of undefined (reading 'pathname')" occurs when we don't set the to prop on a Link component in React...
Read more >Cannot read properties of undefined (reading 'pathname')
TypeError : Cannot read properties of undefined (reading 'pathname'). Do anyone have experience with this error?
Read more >typeerror: cannot read properties of undefined ... - You.com
pathname is undefined because you've not correctly accessed it from the (presumably) passed location prop from route props. You've missed the props part....
Read more >React Router: Cannot read property 'pathname' of undefined ...
[Solved]-React Router: Cannot read property 'pathname' of undefined-Reactjs · score:29. Accepted answer. The error is because the api in React Router v4 is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For me, this arrived when I had not passed the value of prop “to” in NavLink. I hope this may work for a few people over here. 😄
Found a solution. Do not define a router props when combining reducers, but pass it in the createStore call as connectRouter(history)(rootReducer), f.e.
root-reducer.js
store.js
Worked like charm for me.