Javascript 浏览器返回不呈现我的上一页

Javascript 浏览器返回不呈现我的上一页,javascript,ember.js,Javascript,Ember.js,这是我的密码。我面临两个问题。 1.在窗体中单击“浏览器后退”按钮时不呈现窗体列表 2.当我刷新页面时,它不会再次调用render方法 App.Router.map(function() { this.resource('formList', { path: '/formList' }, function() { this.route('form'); }); }); App.IndexRoute = Ember.Route.extend({ redi

这是我的密码。我面临两个问题。 1.在窗体中单击“浏览器后退”按钮时不呈现窗体列表 2.当我刷新页面时,它不会再次调用render方法

App.Router.map(function() {
    this.resource('formList', { path: '/formList' }, function() {
        this.route('form');
    });
});

App.IndexRoute = Ember.Route.extend({

    redirect : function() {
        this.transitionTo('formList');
    }
});

App.FormListFormRoute = Ember.Route.extend({

    renderTemplate: function(){
        this.render('formListForm', {
            into:'application',
            outlet: 'appBody'
        });
    }
});

App.FormListRoute = Ember.Route.extend({

    renderTemplate: function(){
        this.render('formList', {
            into:'application',
            outlet: 'appBody'
        });
    }
});

formList
formListForm
的父级。它应该在dom中同样存在。不幸的是,当您访问
formListForm
时,您正在从dom中删除
formList
,但是Ember没有意识到这一点,并且有这样的印象,因为您的路由器在页面中已经存在
formList
,因此它不会浪费任何时间重新呈现已经存在的内容

尽管如此,手动渲染是不必要的。默认情况下,Ember将使树下的每个路由/资源进入父资源的空
{{outlet}
。从应用程序模板(应用程序的根或
/
)开始。我已经改写了你的例子

应用程序模板

欢迎来到Ember.js
{{链接到“表单列表表单”“表单列表.表单”}
{{outlet}}
表单列表模板

表格清单
始终显示在表单列表中的信息
{{outlet}}
表单列表索引模板

仅在访问/formList时显示在表单列表中的信息
表单列表表单模板

查看表单路径
示范一下

您可以用您的示例创建一个新的示例吗?通常,您不需要覆盖renderTemplate函数,如果您正确定义了模板anc类并且案例符合正常场景,则Ember将正确呈现模板。
  <script type="text/x-handlebars" data-template-name='application'>
    <h2> Welcome to Ember.js</h2>

    {{link-to 'Form List Form' 'formList.form'}}

    {{outlet}}
  </script>
  <script type="text/x-handlebars" data-template-name="formList">
    <h2 class='formList'> Form List</h2>
    <h4 class='formList'>Info that always shows up in the form list</h4>
    {{outlet}}
  </script>
   <script type="text/x-handlebars" data-template-name="formList/index">
   <h4 class='formListIndex'>Info that only shows up in the form list when visiting /formList</h4>
  </script>
  <script type="text/x-handlebars" data-template-name="formList/form">
   <h4 class='formListForm'> Viewing the form route</h4>
  </script>