アプリケーションがユーザー モデルの選択を追跡するために必要なネストされたルート階層があります。メイン アプリケーション テンプレートを使用して、各ルートをそのテンプレートの単一のアウトレットにレンダリングしようとしています。これは、親から子へとルート階層をたどる際に機能します。
ただし、ブラウザの戻るボタンをクリックしてルート階層に戻ると、親ルートの 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 です。リンクをクリックしてルートをたどり、ブラウザの [戻る] ボタンをクリックすると、アプリケーション テンプレートがレンダリングされ、アウトレットには何もフックされません。
再レンダリングを強制する方法はありますか、それとも間違った方法で行っていますか?