react-router 1.0错误:未捕获TypeError:getCurrentLocation不是函数| createHistory.js

时间:2015-10-31 17:46:37

标签: javascript reactjs react-router

获取未捕获的TypeError:getCurrentLocation在实现react-router时不是createHistory.js中的函数。我的代码出了什么问题?

var React = require('react');
var ReactDOM = require('react-dom');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var IndexRoute = ReactRouter.IndexRoute;
var history = require('history');
var createHistory = require('history/lib/createHistory');
var useBasename = require('history/lib/useBasename');


var Login = require('./components/login');
var App = require('./components/App');


var appHistory  = useBasename(createHistory)({
  basename: '/test'
})

ReactDOM.render((
  <Router history={appHistory}>
    <Route path="/" component={App}>
      <Route path="login" component={Login}/>      
      <IndexRoute component={Login}/>
    </Route>
  </Router>
), document.getElementById('content'));

1 个答案:

答案 0 :(得分:1)

您不应该直接使用createHistory包中的history。而是使用其中一个实际的历史工厂,例如createBrowserHistorycreateHashHistory