繁体   English   中英

错误:断言失败:URL“/”与应用程序中的任何路由都不匹配

[英]Error: Assertion Failed: The URL '/' did not match any routes in your application

我正在测试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'模板和相应的控制器,您甚至无需在路由器中明确命名它,因此您根本不必包含索引路由。

如果你想保留它可以使用:

App.Router.map(function(){
    this.route('index', { path: '/' });
    this.route('history');
});

有关Ember为什么已在此处路由/ 'index'更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM