获取未捕获的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'));
答案 0 :(得分:1)
您不应该直接使用createHistory
包中的history
。而是使用其中一个实际的历史工厂,例如createBrowserHistory
或createHashHistory
。