Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs only redirect to default route if no subroute is specified

I'm trying to redirect /dashboard/ to /dashboard/reach/demographic if the url hits /dashboard/.

Problem is, I still get redirected to /dashboard/reach/demographic/ if I hit a subroute like **/dashboard/traffic.

What is the Ember way of doing this?

Here is my code:

(function() {
    App.Router.map(function(match) {
      this.resource('dashboard', function() {
        this.resource('traffic', function() {
          this.route('visits');
          this.route('pageviews');
          return this.route('duration');
        });
        return this.resource('reach', function() {
          this.route('demographics');
          this.route('over_time');
          return this.route('devices');
        });
      });
      return this.route('audience');
    });

    App.DashboardRoute = Ember.Route.extend({
      redirect: function() {
        return this.transitionTo('reach.demographics');
      }
    });

    if (!App.ie()) {
      App.Router.reopen({
        location: 'history'
      });
    }

    App.reopen({
      rootUrl: '/'
    });

  }).call(this);
like image 831
Dennis Avatar asked Aug 02 '13 09:08

Dennis


1 Answers

Implement redirect in DashboardIndexRoute instead of DashboardRoute.

App.DashboardIndexRoute = Ember.Route.extend({
  redirect: function() {
    return this.transitionTo('reach.demographics');
  }
});

I created a jsbin example for you. Try:

http://jsbin.com/odekus/6#/dashboard/

http://jsbin.com/odekus/6#/dashboard/traffic

I also removed unnecessary return's from the code.

like image 73
jaaksarv Avatar answered Sep 20 '22 12:09

jaaksarv