小编Rus*_*ith的帖子

嵌套路由渲染到相同的模板/插座中断浏览器后退按钮单击

我有一个嵌套的路由层次结构,我需要我的应用程序来跟踪用户模型选择.我正在尝试使用主应用程序模板,并将每个路径渲染到该模板上的单个插座中.当我遍历从父级到子级的路由层次结构时,这是有效的.

但是,一旦单击浏览器后退按钮以返回路径层次结构,父路由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"
})}});
Run Code Online (Sandbox Code Playgroud)

使用模板:

<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 …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-router

13
推荐指数
1
解决办法
7127
查看次数

标签 统计

ember-router ×1

ember.js ×1