我有一个嵌套的路由层次结构,我的应用程序需要它来跟踪用户模型选择。我正在尝试使用主应用程序模板并将每个路由呈现到该模板上的单个插座中。这在我从父级到子级遍历路由层次结构时起作用。
但是,一旦您单击浏览器后退按钮以返回路由层次结构,父路由 renderTemplate 挂钩就不会触发。这会导致孩子从插座上脱钩,并且没有任何东西返回到插座中。
这是一个例子:
App = Ember.Application.create({});
App.Router.map(function(){
this.resource("animals", function(){
this.resource("pets", function(){
this.route('new')
})
})
});
App.PetsView = Ember.View.extend({
templateName : 'wild/pets'
});
App.AnimalsRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({
into: "application",
outlet : "A"
})
}});
App.PetsRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({
into: "application",
outlet : "A"
})}});
App.PetsNewRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({
into: "application",
outlet : "A"
})}});
使用模板:
<script type="text/x-handlebars" data-template-name="application">
<h1>{{#linkTo "animals"}}Hello from Ember.js</h1>{{/linkTo}}
{{outlet A}}
</script>
<script type="text/x-handlebars" data-template-name="animals">
{{#linkTo "pets"}}This is animals list{{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="wild/pets">
{{#linkTo "pets.new"}}This is pets list{{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="pets/new">
This is pet creation
</script>
这是一个带有这段代码的jsfiddle。单击链接以遍历路线,然后单击浏览器后退按钮,应用程序模板被渲染,没有任何东西连接到它的出口。
有没有办法强制重新渲染,或者我是不是走错了路?