我正在测试 Ember.js 框架,但在尝试加载页面时遇到了问题。目前我在一个页面上有两个链接,我只是想弄清楚如何让其中一条路线显示在 {{outlet}} 中。每当我尝试加载页面时,我都会在控制台中收到此错误 - 未捕获错误:断言失败:错误:断言失败:URL“/”与应用程序中的任何路由都不匹配
这是我的 HTML 文件
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link rel ="stylesheet" href="css/normalize.css">
<link rel ="stylesheet" href="css/style.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.1.0/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
<div>
{{#link-to 'index'}} Home {{/link-to}}
{{#link-to 'history'}} History {{/link-to}}
</div>
<div>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index">
<h1> Index Route Test</h1>
</script>
<script type="text/x-handlebars" data-template-name="history">
<h1> History Route Test</h1>
</script>
</body>
</html>
这是我的JS文件
var App = Ember.Application.create({
LOG_TRANSITIONS:true
});
App.Router.map(function(){
this.route('index');
this.route('history');
});
App.IndexRoute=Ember.Route.Extend({
});
最佳答案
Ember 自动将 /
路由到您的 'index'
模板和相应的 Controller ,您甚至无需在路由器中明确命名它,因此您不必包含索引路线。
如果你想保留它,你可以使用:
App.Router.map(function(){
this.route('index', { path: '/' });
this.route('history');
});
关于为什么 Ember 已经将 /
路由到 'index'
的更多信息 here .
关于javascript - 错误 : Assertion Failed: The URL '/' did not match any routes in your application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24358081/