gpt4 book ai didi

reactjs - 使用react-router时参数列表后缺少 )

转载 作者:行者123 更新时间:2023-12-03 14:21:56 24 4
gpt4 key购买 nike

我正在使用 React-router v0.13.3 和 React 0.13.3 构建一个简单的 Web 应用程序。但是当我尝试与 React-Router 集成时出现了一个大问题。

所以,这是错误消息:未捕获的语法错误:参数列表后缺少 )

app.jsx

  var Router = window.ReactRouter;
var Route = Router.Route;

app.VIEW_SEARCH = 'search_view';
app.VIEW_FAVORITE = 'favorite_view';
app.VIEW_RESULT = 'result_view';

var RouteHandler = Router.RouteHandler;
var App = React.createClass({
render () {
return (
<div>
<h1>App</h1>
<RouteHandler/>
</div>
)
}
});

// declare our routes and their hierarchy
var routes = (
<Route handler={App} path="/">
<Route path="search" handler={app.SearchView}/>
<Route path="about" handler={app.AboutView}/>
<Router.DefaultRoute handler={app.SearchView}/>
</Route>
);

Router.run(routes, Router.HistoryLocation, (Root) => {
React.render(<Root/>, document.body);
});

上面粘贴了主要的JavaScript代码,当我添加最后3行时出现错误。 Web 应用程序使用 Bower 来管理依赖项。

如果我使用

  Router.run(routes, Router.HistoryLocation, function(handler) {
React.render(<handler/>, document.body);
});

替换最后 3 行。屏幕上什么也没有显示。有谁知道怎么解决吗?

最佳答案

括号错误可能是因为 arrow function你用。这是 ecmascript 6 的一项功能,不幸的是,目前大多数浏览器还不支持。

由于你使用gulp,所以你很容易添加babel到您的构建步骤。否则,只需使用“旧”符号:function(Root) {return ...}

至于您在评论中指出的第二个问题,我们需要 Root 的源代码来尝试了解发生了什么。

关于reactjs - 使用react-router时参数列表后缺少 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31118454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com