Add `redirect` option to Router

I created PR #2363 which adds the possibility to specify the redirect on an Ember.Route as String. Now that I think of it, it would be nice to specify this redirection without having to write a route.

So this

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

would be specified in the router mapping

App.Router.map(function() {
  this.route('home', { path: '/', redirect: 'teams' })
  this.resource('teams', function() {
    this.route('index', { redirect: 'favorites' });
    this.route('favorites');
    this.route('all');
  });
});

What do you think?

Maybe this could be further simplified:

App.Router.map(function() {
  this.route('home', { path: '/', redirect: 'teams' })
  this.resource('teams', { index: 'favorites' }, function() {
    this.route('favorites');
    this.route('all');
  });
});
4 Likes

Why not just put the favorites under teams.index instead of teams.favorites with a redirect from index?

I guess you’re right. In this case it’s just the naming: so favorites is basically the index route. But the “redirect from index” part remains. So currently I would need to write an App.IndexRoute which simply redirects to teams - it would be convenient if this were be possible by specifying in the router mapping, wouldn’t it?

Yes, that does make total sense :slight_smile: I’m +1 for this idea.

We were talking about this today and I’m not surprised to do see this already posted as an extension to the router.