所以我的index.js
文件有一个非常基本的设置,我的所有路由都被保存。我从控制台得到了上面的TypeError
,但我不确定为什么。以下是我的代码:
const React = require('react');
const ReactDOM = require('react-dom');
// React router goodies
import { Router, Route, browserHistory, IndexRoute, hashHistory } from 'react-router';
const App = require('./components/App.jsx');
ReactDOM.render(
<Router history = {browserHistory}>
<Route path="/" component={App}>
</Route>
</Router>,
document.getElementById('app')
);
答案 0 :(得分:5)
browserHistory
,此处提出了问题 - Can no longer import { IndexRoute, browserHistory } from version 4.
切换到版本3.0.0
或使用BrowserRouter进行修复。
对于版本3.0.0
:
"dependencies": {
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-router": "^3.0.0",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
}
对于版本4.0.0
:
const React = require('react');
const ReactDOM = require('react-dom');
import { BrowserRouter, Route } from 'react-router-dom';
const App = require('./components/App.jsx');
ReactDOM.render(
<BrowserRouter>
<Route path="/" component={App}>
</Route>
</BrowserRouter>,
document.getElementById('app')
);