javascript 反应路由器:运行不是一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32682854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
react-router : run is not a function
提问by Nick Pineda
A Egghead tutorial teaches it like this:
Egghead 教程是这样教的:
var React = require('react');
var Router = require('react-router');
var routes = require('./config/routes');
Router.run(routes, function(Root){
React.render(<Root />, document.getElementById('app'));
});
Yet I get this error:
但我收到此错误:
Uncaught TypeError: Router.run is not a function
未捕获的类型错误:Router.run 不是函数
note:
I've already updated react-routerto the recent version.
注意:我已经更新react-router到最新版本。
回答by Eelke
Since the release of React Router v1.0, the runmethod has been removed, these breaking changes are documented in the upgrade guide. Your code would roughly translate to this:
自 React Router v1.0 发布以来,该run方法已被删除,这些重大更改记录在升级指南中。您的代码将大致转换为:
ReactDOM.render(<Router>{routes}</Router>, document.getElementById('app'))
https://github.com/rackt/react-router/blob/832c42946c874fe56ffde0066b1088054311cb98/CHANGES.md
https://github.com/rackt/react-router/blob/832c42946c874fe56ffde0066b1088054311cb98/CHANGES.md

