[英]DefaultRoute throws “Cannot call a class as a function”
I'm using react-router with ES6 classes and it keeps throwing the error 我在ES6类上使用react-router,并且不断抛出错误
Uncaught TypeError: Cannot call a class as a function
未捕获的TypeError:无法将类作为函数调用
It refers to the declaration of the default route. 它引用默认路由的声明。 Most of the code is taken from the example in the react-router repo, which is why I'm wondering why it's buggy.
大多数代码取自react-router存储库中的示例,这就是为什么我想知道为什么它有问题。
import React from 'react';
import Router from 'react-router';
import {Header} from './components/Header.react.jsx';
var DefaultRoute = Router.DefaultRoute;
var Link = Router.Link;
var Route = Router.Route;
var RouteHandler = Router.RouteHandler;
var App = React.createFactory(React.createClass({
render: function () {
return (
<div>
<Header />
<RouteHandler />
</div>
);
}
}));
var Inbox = React.createClass({
render: function () {
return (
<div>
test
</div>
);
}
});
var routes = (
<Route name="app" path="/" handler={App}>
<DefaultRoute handler={Inbox}/> // ERROR
</Route>
);
Router.run(routes, Router.HistoryLocation, function (Handler) {
React.render(<Handler/>, document.body);
});
Why are you wrapping App
component creation with createFactory
call? 为什么用
createFactory
调用包装App
组件的创建?
The following works just fine with me (I just removed Header
since it is external): 以下对我来说很好用(由于它是外部的,因此我刚刚删除了
Header
):
import React from 'react';
import Router from 'react-router';
var DefaultRoute = Router.DefaultRoute;
var Link = Router.Link;
var Route = Router.Route;
var RouteHandler = Router.RouteHandler;
var App = React.createClass({
render: function () {
return (
<div>
<RouteHandler />
</div>
);
}
});
var Inbox = React.createClass({
render: function () {
return (
<div>
test2
</div>
);
}
});
var routes = (
<Route name="app" path="/" handler={App}>
<DefaultRoute handler={Inbox}/> // ERROR
</Route>
);
Router.run(routes, Router.HistoryLocation, function (Handler) {
React.render(<Handler/>, document.body);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.