0
我無法弄清楚爲什麼這個設置不起作用。我一直試圖解決這個問題,現在約10個小時。我使用history 3.2.1
,react-router 3.0.2
和react-router-redux 4.0.7
,webpack 1.14.0
具體定義哈希歷史,但---無法讀取屬性'getCurrentLocation'未定義(...)
這種設置工作完全正常的發展,但一旦包裝不工作,因爲,它看起來像,hashHistory快到了不確定的。用於生產和開發的configureStore沒有實質性差異。
所有涉及的變量都在devtools確認執行時被定義。我認爲問題是我的routes.js
也許加載(見下圖)
任何人都可以提供的幫助將非常感激。謝謝閱讀。
錯誤:
Cannot read property 'getCurrentLocation' of undefined(…)
configureStore.production.js
import { applyMiddleware, createStore, compose } from 'redux';
import { responsiveStoreEnhancer } from 'redux-responsive';
import thunk from 'redux-thunk';
import { routerMiddleware, push } from 'react-router-redux';
import rootReducer from '../reducers';
import storage from '../utils/storage';
import * as noteActions from '../actions/notes_actions';
var createHistory = require('history').createHashHistory;
const hashHistory = createHistory();
const actionCreators = {
...noteActions,
push,
};
const router = routerMiddleware(hashHistory);
const enhancer = compose(
responsiveStoreEnhancer,
applyMiddleware(thunk, router),
storage(),
);
export default function configureStore(initialState: Object | void) {
return createStore(rootReducer, initialState, enhancer);
}
Index.js
import _ from 'lodash';
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import storage from 'electron-json-storage';
import { syncHistoryWithStore } from 'react-router-redux';
import * as applicationUtils from './utils/functions';
import configureStore from './store/configureStore';
import myRoutes from './routes';
import './app.global.css';
var Router = require('react-router').Router;
var createHistory = require('history').createHashHistory;
let applicationState;
let stateKeyPresent;
let createStore;
let myHistory;
const hashHistory = createHistory();
function createStoreFunction() {
createStore = configureStore(applicationState);
myHistory = syncHistoryWithStore(hashHistory, createStore);
render(
<Provider store={createStore}>
<Router history={myHistory} routes={myRoutes} />
</Provider>,
document.getElementById('root')
);
}
storage.keys((err, keys) => {
if (err) throw err;
for (let i = 0; i < keys.length; i++) {
if (keys[i] === 'state') {
stateKeyPresent = keys[i];
}
};
});
let getStoredState = new Promise(function(resolve,reject) {
storage.get('state', (err, data) => {
if (!stateKeyPresent) {
applicationState = {};
resolve();
} else if (data) {
applicationState = JSON.parse(data);
resolve();
} else {
applicationState = {};
resolve();
}
});
});
getStoredState.then(() => {
createStoreFunction()
});
感謝您的回覆!不幸的是我安裝它作爲解決這個問題的嘗試。使用反應路由器中的歷史記錄結果相同。 – Slbox
它已被正確卸載?只是要求確保問題不是其他問題。你有沒有檢查過你的'package.json'它是否有正確的依賴關係? – WitVault
是的,一切都有正確的依賴關係,我可以告訴。 'npm'不會告訴我任何錯誤,無效的同伴,缺少的依賴關係等,我也找不到任何我自己。 – Slbox