gpt4 book ai didi

ember.js - 访问顶级资源时转换到另一个路由,但访问嵌套路由时不转换

转载 作者:行者123 更新时间:2023-12-01 01:08:01 24 4
gpt4 key购买 nike

我定义了以下路线:

SettingsApp.Router.map(function () {
....
this.resource('profile', function () {
this.route('user'),
this.route('company')
});

});

SettingsApp.ProfileRoute = Ember.Route.extend({
redirect: function () {
this.transitionTo('profile.user');
},
model: function () {
return Ember.A([
Ember.Object.create({title:"User", link:"#/profile/user"}),
Ember.Object.create({title:"Company", link:"#/profile/company"})
]);
}
})
#/profile重定向到 #/profile/user ,正如预期的那样,但问题是 #/profile/company也重定向到 #/profile/user .每当我访问该资源下方的任何 url 时,似乎都会遵循资源重定向。

为什么是这样?如何仅重定向顶级 #/profile ?

最佳答案

您可以移动您的 redirect()profile资源index路线, ProfileIndexRoute ,只有当您浏览到 #/profile 时才会触发它并允许您访问 #/profile/user#/profile/company没有问题:

SettingsApp.Router.map(function () {
this.resource('profile', function () {
this.route('user');
this.route('company');
});

});

SettingsApp.ProfileRoute = Ember.Route.extend({
//redirect: function () {
// this.transitionTo('profile.user');
//},
model: function () {
return Ember.A([
Ember.Object.create({title:"User", link:"#/profile/user"}),
Ember.Object.create({title:"Company", link:"#/profile/company"})
]);
}
});


SettingsApp.ProfileIndexRoute = Ember.Route.extend({
redirect: function () {
this.transitionTo('profile.user');
},
});

Example JSBin

提示:设置 LOG_TRANSITIONS: true在您的 Application向您显示正在通过路由器访问哪些路由。这对于调试此类问题非常有帮助。
SettingsApp = Ember.Application.create({
LOG_TRANSITIONS: true
});

关于ember.js - 访问顶级资源时转换到另一个路由,但访问嵌套路由时不转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17209609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com