Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect from index to another route and force model()

Tags:

ember.js

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?

like image 888
kraftwer1 Avatar asked May 29 '13 15:05

kraftwer1


1 Answers

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/

like image 66
davidpett Avatar answered Oct 10 '22 23:10

davidpett