2017-02-22 23 views
0

我無法弄清楚爲什麼這個設置不起作用。我一直試圖解決這個問題,現在約10個小時。我使用history 3.2.1react-router 3.0.2react-router-redux 4.0.7webpack 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() 
}); 

enter image description here

回答

1

嘗試從軟件包依賴項中卸載history npm模塊。

陣營路由器的依賴關係:

"dependencies": { 
    "history": "^3.0.0", 
    "hoist-non-react-statics": "^1.2.0", 
    "invariant": "^2.2.1", 
    "loose-envify": "^1.2.0", 
    "warning": "^3.0.0" 
    }, 

React-router已經進行依賴於它,正確的history版本將與react-router安裝進行安裝。

您無需單獨安裝。

嘗試

npm uninstall --save history react-router 

然後

install --save [email protected]_version 

一次。

檢查它是否有效。

+0

感謝您的回覆!不幸的是我安裝它作爲解決這個問題的嘗試。使用反應路由器中的歷史記錄結果相同。 – Slbox

+0

它已被正確卸載?只是要求確保問題不是其他問題。你有沒有檢查過你的'package.json'它是否有正確的依賴關係? – WitVault

+0

是的,一切都有正確的依賴關係,我可以告訴。 'npm'不會告訴我任何錯誤,無效的同伴,缺少的依賴關係等,我也找不到任何我自己。 – Slbox

相關問題