问题描述
如果网址匹配 / dashboard / ,我正在尝试将 / dashboard / 重定向到 / dashboard / reach / p> 问题是,如果我点击像/ / dashboard / traffic这样的子路由,我仍然重定向到 / dashboard / reach / demographic / p> Ember的这种方式是什么? 这是我的代码: 在DashboardIndexRoute中实现重定向,而不是DashboardRoute。 我为您创建了一个jsbin示例。尝试: 我还从代码中删除了不必要的退货。 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: Implement redirect in DashboardIndexRoute instead of DashboardRoute. 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. 这篇关于如果没有指定subroute,Emberjs将重定向到默认路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
(function(){
App.Router.map(function(match){
this.resource('dashboard',function ){
this.resource('traffic',function(){
this.route('visits');
this.route('pageviews');
返回此.route('duration');
});
返回this.resource('reach',function(){
this.route('demographics');
this .route('over_time');
return this.route('devices');
});
});
return this.route观众');
});
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);
App.DashboardIndexRoute = Ember.Route.extend({
redirect:function(){
return this.transitionTo('reach.demographics');
}
});
(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);
App.DashboardIndexRoute = Ember.Route.extend({
redirect: function() {
return this.transitionTo('reach.demographics');
}
});