redux-router: Uncaught TypeError: Cannot read property 'location' of undefined
Version Latest Version
History: ^2.1.2 React Router: ^3.0.0
Steps to reproduce
const createStoreWithMiddleware = compose(applyMiddleware(reduxThunk, logger),
reduxReactRouter({ routes, createHistory }));
const store = createStoreWithMiddleware(createStore)(rootReducer);
ReactDOM.render(
<Provider store={store}>
<ReduxRouter>
<Route path="/">
<Route path="login" component={Login} />
<Route path="/" component={App}>
<IndexRoute component={Welcome} onEnter={RequireAuth} />
<Route path='logout' component={Logout} onEnter={RequireAuth} />
</Route>
</Route>
</ReduxRouter>
</Provider>
, document.querySelector('.main')
);
Actual Behavior
When I ran my code it return me Uncaught TypeError: Cannot read property 'location' of undefined
any solution?
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 30 (4 by maintainers)
Commits related to this issue
- Downgrade version of react-router because fail. https://github.com/acdlite/redux-router/issues/281 — committed to wadobo/socializa by Virako 7 years ago
Try to import BrowserRouter:
import {BrowserRouter as Router, Route} from 'react-router-dom';
//“react”: “^16.2.0”, //“react-dom”: “^16.2.0” //“react-router-dom”: “^4.2.2”,npm install react-router@3.0.5
‘BrowserRouter as Router’ It has to exist,or else will be error.
+1 I have same issue from react-router v4.0
@thanhnhan2tn use v3.0.0 it will work
I have upgraded my react router to 4.1.1, and history 4.6.1 and I am facing same issue
Uncaught TypeError: Cannot read property ‘location’ of undefined at new Router (Router.js:31)
Without changing version, is it possible to fix in the code?
v3.0.0 is working no issues
As sky-gg said, We have to include ->‘BrowserRouter as Router’ It has to exist,or else will be error.
The error got cleared and page loaded successfully 😃
I’ve run into this issue with history@3 as well. I tried reverting to history@2 but that then produces the error
history.getCurrentLocation is not a function
. Tried to work out what was happening myself, but too many libraries I’m not very familiar with. I created a repo based on the “basic example” to try and get anyone else up and running who might be more capable of looking into this.I can confirm that using
react-router
v2.8.1 fixes this problem.@gazpachu I haven’t tried adding redux yet, but to get basic routing to work, I had to use the following versions:
Those were downgraded from react@16, react-dom@16, and react-router@4.x.