Emberjs only redirect to default route if no subroute is specified

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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); 

回答1:

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!