我在使用 ember.js 指定路由器的位置属性时遇到了一些问题。我有以下代码,如果我没有将 App.Router 的位置设置为“历史记录”,则该代码有效。当我设置它时,当它尝试加载页面时,控制台显示以下错误:未捕获的错误:没有路由匹配 URL '/test/' - 其中 /test/ 是我在 /var/www/ 中的目录。这是代码:
应用程序.js
window.App = Em.Application.create({
title: 'Title'
});
App.ApplicationView = Ember.View.extend({
templateName: 'application'
})
App.ApplicationController = Ember.Controller.extend({
name: 'test'
})
App.IndexAboutView = Ember.View.extend({
templateName: 'index/about'
})
App.IndexAboutController = Ember.Controller.extend({
str: 'my string'
})
App.IndexBioView = Ember.View.extend({
templateName: 'index/bio'
})
App.IndexBioController = Ember.Controller.extend({
str: 'bio text'
})
App.Router.reopen({
location: 'history'
});
App.Router.map(function(match){
this.resource('index', { path: '/' }, function() {
this.route('about');
this.route('bio');
})
})
我的索引文件看起来像:
<script type="text/x-handlebars" data-template-name="application">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar collapsed" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="brand">
{{#linkTo "index"}}{{unbound App.title}}{{/linkTo}}
</div>
<div class="nav-collapse navbar-responsive-collapse collapse">
<ul class="nav">
<li><a href="#">a</a></li>
<li><a href="#">b</a></li>
<li><a href="#">c</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index/about">
This is the str from about : {{str}}
</script>
<script type="text/x-handlebars" data-template-name="index/bio">
This is the str from bio : {{str}}
</script>