gpt4 book ai didi

javascript - 嵌套资源和路径

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

我想在 Ember 中嵌套资源,但能够通过短 URL 访问它们。

例如:mysite.com/admin 将打开路由:/routes/profiles/settings/admin

是否可以使用 Ember 做类似的事情?我目前正在使用 Ember 1.7 和 Ember App Kit。

我尝试了以下方法,但不起作用:

var Router = Ember.Router.extend();

Router.map(function () {
this.resource('profile', function () {
this.resource('profile.settings', { path: '/settings' }, function () {
this.resource('profile.settings.admin', { path: '/admin' });
);
});

谢谢。

最佳答案

您的代码不起作用,因为您最内部的资源从最外部的资源继承了 /profile 路径,并从中间的资源继承了 /settings 路径。如果您希望它只是简单的 /admin,您必须执行以下操作:

this.resource('profile', { path: '' }, function() {
this.resource('profile.settings', { path: '' }, function() {
this.resource('profile.settings.admin', { path: '/admin' });
});
});

但是,当您有更多的路由并且每条路由都需要顶级路径时,这将变得非常棘手。您可能会发现在顶层声明一个 admin 路由,然后使用 redirect 进行重定向会更容易。 Hook 在 route 。

关于javascript - 嵌套资源和路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25692961/

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