我正在测试React-Router,目前我的所有代码都在index.html文件中。当我运行应用程序时,我收到以下错误:
Uncaught TypeError: Cannot read property 'getCurrentLocation' of undefined
at Object.createTransitionManager (ReactRouter.min.js:1)
at Object.componentWillMount (ReactRouter.min.js:1)
at react-dom.js:4802
at measureLifeCyclePerf (react-dom.js:4529)
at ReactCompositeComponentWrapper.performInitialMount (react-dom.js:4801)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4712)
at Object.mountComponent (react-dom.js:11542)
at ReactCompositeComponentWrapper.performInitialMount (react-dom.js:4825)
at ReactCompositeComponentWrapper.mountComponent (react-dom.js:4712)
at Object.mountComponent (react-dom.js:11542)
这是我的代码。请注意,此代码位于index.html文件中。
var App = React.createClass({
render: function() {
return (
<div>
<h1>My App</h1>
<ul>
<li>Home</li>
<li>Stuff</li>
<li>Contact</li>
</ul>
<div>
content
</div>
</div>
);
}
});
ReactDOM.render(
<ReactRouter.Router>
<ReactRouter.Route path="/" component={App}>
</ReactRouter.Route>
</ReactRouter.Router>,
container
);
</script>
答案 0 :(得分:0)
您遗漏了history
定义中的Router
道具。添加它,我认为错误应该消失
var browserHistory=ReactRouter.browserHistory;
ReactDOM.render(
<ReactRouter.Router history={browserHistory}>
<ReactRouter.Route path="/" component={App}>
</ReactRouter.Route>
</ReactRouter.Router>,
container
);