I'd like to forward the user to /articles
when he arrives at /
. Unfortunately, /articles
's model()
-function will not be executed because it's not a page refresh:
App.IndexRoute = Em.Route.extend
redirect: ->
@transitionTo "articles"
What's the Ember-way to achieve this?
I can't really tell the rest of your setup, but this is how I achieve it
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();
}
});
working example: http://jsbin.com/imidiq/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With