7

我想将用户转发到/articles他到达时/。不幸的是,/articles's model()-function 不会被执行,因为它不是页面刷新:

App.IndexRoute = Em.Route.extend
    redirect: ->
        @transitionTo "articles"

实现这一目标的 Ember 方式是什么?

4

1 回答 1

8

我无法真正说出您的其余设置,但这就是我实现它的方式

window.App = Ember.Application.create();

App.Store = DS.Store.extend({
  adapter: DS.FixtureAdapter
});

App.Router.map(function() {
  this.resource('articles', function() {
    this.resource('article', {path: ':article_id'});
  });
});

App.Article = DS.Model.extend({
  title: DS.attr('string')
});

App.Article.FIXTURES = [{
  id: 1,
  title: 'blah'
}, {
  id: 2,
  title: 'more blah'
}];

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
   this.transitionTo('articles'); 
  }
});

App.ArticlesRoute = Ember.Route.extend({
  model: function() {
    return App.Article.find();
  }
});

工作示例:http: //jsbin.com/imidiq/2/

于 2013-05-30T23:50:09.237 回答