尝试在我的本地机器上运行任何(和所有)React-Router 示例https://github.com/rackt/react-router/tree/master/examples而仅将 ES6 语法更改为 ES5 我不断收到相同的错误来自同一行代码
代码
Router.run(routes, function (Handler) {
错误
Cannot read property 'validateProps' of undefined
除了使用 ES6 声明依赖项和解构路由器之外,我没有更改示例的任何内容
var React = require('react');
var Router = require('react-router');
var { Route, RouteHandler, Link } = Router;
我在我的索引中包含了指向 js 文件的链接,并为路由器做了这个
var Route = Router[0];
var RouteHandler = Router[1];
var Link = Router[2];
这是粘贴在这里的 ES5 版本代码的 jsfiddle从 github
这是我试图开始工作的 ES5/6 更改的完整代码
var Route = Router[0];
var RouteHandler = Router[1];
var Link = Router[2];
var App = React.createClass({
render: function () {
return (
<div>
<ol>
<li><Link to="home">Home</Link></li>
<li><Link to="signin">Sign in</Link></li>
<li><Link to="forgot-password">Forgot Password</Link></li>
</ol>
<RouteHandler/>
</div>
);
}
});
var SignedIn = React.createClass({
render: function () {
return (
<div>
<h2>Signed In</h2>
<RouteHandler/>
</div>
);
}
});
var Home = React.createClass({
render: function () {
return (
<h3>Welcome home!</h3>
);
}
});
var SignedOut = React.createClass({
render: function () {
return (
<div>
<h2>Signed Out</h2>
<RouteHandler/>
</div>
);
}
});
var SignIn = React.createClass({
render: function () {
return (
<h3>Please sign in.</h3>
);
}
});
var ForgotPassword = React.createClass({
render: function () {
return (
<h3>Forgot your password?</h3>
);
}
});
var routes = (
<Route handler={App}>
<Route handler={SignedOut}>
<Route name="signin" handler={SignIn}/>
<Route name="forgot-password" handler={ForgotPassword}/>
</Route>
<Route handler={SignedIn}>
<Route name="home" handler={Home}/>
</Route>
</Route>
);
Router.run(routes, function (Handler) {
React.render(<Handler/>, document.getElementById('example'));
});