我不明白为什么以下代码会在标题中产生错误。我检查了类似的问题,但我没有发现它们有用。
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { createHashHistory } from 'history';
import Menu from './pages/Menu';
import BookShelf from './pages/BookShelf';
import BorrowBook from './pages/BorrowBook';
const App = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
render() {
return (
<Menu />
);
}
});
ReactDOM.render((
<Router history={browserHistory} onUpdate={() => window.scrollTo(0, 0)}>
<Route path="/" component={App}/>
<Route path="/menu" component={Menu} />
<Route path="/bookshelf" component={BookShelf} />
<Route path="/borrowbook/:bookId" component={BorrowBook} />
</Router>,
document.getElementById('app')
));
答案 0 :(得分:2)
ReactDOM.render(( // extra parenthesis here
<Router history={browserHistory} onUpdate={() => window.scrollTo(0, 0)}>
<Route path="/" component={App}/>
<Route path="/menu" component={Menu} />
<Route path="/bookshelf" component={BookShelf} />
<Route path="/borrowbook/:bookId" component={BorrowBook} />
</Router>,
document.getElementById('app')
)); // extra parenthesis here
额外的括号正在使它实际上传递一个参数而不是两个。