Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:断言失败:URL'/';未匹配应用程序中的任何路由_Javascript_Html_Web_Ember.js_Routes - Fatal编程技术网

Javascript 错误:断言失败:URL'/';未匹配应用程序中的任何路由

Javascript 错误:断言失败:URL'/';未匹配应用程序中的任何路由,javascript,html,web,ember.js,routes,Javascript,Html,Web,Ember.js,Routes,我正在测试Ember.js框架,在尝试加载页面时遇到了问题。目前,我在一个页面上有两个链接,我只是想弄清楚如何在{{outlet}中显示其中一个路由。每当我尝试加载页面时,我都会在控制台中收到此错误-未捕获错误:断言失败:错误:断言失败:URL“/”与应用程序中的任何路由都不匹配 这是我的HTML文件 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <

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

Ember会自动将
/
路由到您的
'index'
模板和相应的控制器,而您甚至不必在路由器中显式命名它,因此您根本不必包含索引路由

如果您想将其保存在中,您可以使用:

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

有关为什么余烬已将
/
路由到
'index'

的详细信息,请尝试删除
此路由('index')从您的
路由器
地图。余烬将为您创建。谢谢。成功了!所以Ember总是自动创建这个。路由('index')?您也不需要指定索引路由,它们是免费的。@TheWaller没问题!没错,我的眼睛完全错过了它。
App.Router.map(function(){
    this.route('index', { path: '/' });
    this.route('history');
});