Ember只渲染根模板

时间:2013-08-30 03:54:07

标签: ember.js

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

这个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>

对此问题的任何见解都将不胜感激。

3 个答案:

答案 0 :(得分:2)

将以下内容添加到您的js文件中,您将不再需要哈希值。

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

答案 1 :(得分:0)

从您的jsbin获取代码并将其粘贴到您的应用程序中,您可能有一个拼写错误或某些代码块,您不应该这样做。我编辑了你的“欢迎”模板,在jsbin中有以下链接,它对我来说很有效。

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

在欢迎链接中,它有一个链接,在“渲染欢迎模板”文本的正下方显示“功能”。当您点击链接时,它会显示“渲染功能模板”。

答案 2 :(得分:0)

好的,我想我在这里看到了这个问题,而这是基于我对ember路线如何运作的误解。我需要在我的网址中包含一个哈希值。所以我的功能网址是/#/ features,而不是/ features。

相关问题