2013-08-30 37 views
0

我试图设置一个应用程序,但我收到了一些奇怪的行为。我有两条路线:“welcome”,它映射到“/”;和“功能”,映射到“/功能”。导航到“/”时,欢迎模板正确呈现。但是,当我导航到“/ features”时,它仍然呈现欢迎模板。Ember只渲染根模板

这个jsbin实际上工作正常:http://jsbin.com/OSoFeYe/1,但下面的代码,这是从我的应用程序,没有。

App.Router.map(function() { 
this.route("welcome", {path: "/"}); 
this.resource("features", {path: "/features"}, function() { 
    this.route("new"); 
    }); 
}); 

App.FeaturesIndexRoute = Ember.Route.extend({ 

}); 



<body> 
    <div class="container"> 

<script type="text/x-handlebars"> 
<h1>rendered application template</h1> 
{{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="features"> 
<h2>Render features</h2> 

<h6>Done features template</h6> 
</script> 

<script type="text/x-handlebars" data-template-name="welcome"> 
<h2>Render welcome</h2> 
</script> 
</div> 
</body> 

任何有关这个问题的见解,将不胜感激。

回答

2

将以下内容添加到您的js文件中,您将不再需要该散列。

App.Router.reopen({ 
    location: 'history' 
}); 
0

从你的jsbin获取代码并将其粘贴到你的应用中,你可能会有一个错误的或者你不应该的代码块。我编辑了你的“欢迎”模板,在jsbin中有以下链接,它对我来说非常合适。

<script type="text/x-handlebars" data-template-name="welcome"> 
    <h2>rendering welcome template</h2> 
    {{#linkTo "features"}}features{{/linkTo}} 
</script> 

在欢迎链接它有一个链接,说“功能”正下方的文字“欢迎渲染模板”。当你点击链接时,它会显示“呈现功能模板”。

+0

所以,功能链接到“http:// localhost:3000/features#/ features”链接,并正确呈现功能模板。但是,如果我转到“http:// localhost:3000/features”,它仍会呈现欢迎模板。 –

0

好吧,我想我在这里看到了这个问题,它是基于我对误差路线的误解。我需要在我的网址中加入散列。所以我的功能网址是/#/功能,而不是/功能。