javascript - 错误 : Assertion Failed: The URL '/' did not match any routes in your application

标签 javascript html web ember.js routes

我正在测试 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/

相关文章:

javascript - 登录网站失败

javascript - 从 angularjs 获取图像名称并在 laravel Blade 中使用它?

html - 将长电子邮件地址包装在小盒子中

javascript - 如何将utf8编码的html嵌入到元素中

javascript - 如何检测 div 的内容何时被卸载?

javascript - Firebase getIdToken 不起作用

Java智能卡认证PKI

javascript - 当 Angular 完成渲染 Controller 的模板时执行一个函数

javascript - 替代 normalize() 对数组进行排序

java - JFreeChart表格的X轴?