我希望用户在/articles
到达时将其转发至/
。遗憾的是,/articles
' model()
- 函数将无法执行,因为它不是页面刷新:
App.IndexRoute = Em.Route.extend
redirect: ->
@transitionTo "articles"
实现这一目标的Ember方式是什么?
答案 0 :(得分: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();
}
});