嵌套的资源和路径
Nested resources and path
我想在Ember中嵌套资源,但可以使用短URL访问它们。
例如:mysite.com/admin将打开路由:/routes/profiles/settings/admin
有可能用Ember做这样的事情吗?我目前正在使用Ember1.7和EmberAppKit。
我尝试了以下操作,但不起作用:
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
路由,然后使用路由中的重定向挂钩进行重定向会更容易。
相关文章:
- Javascript:使用绝对路径设置img src
- 如何在d3.js中返回路径的y坐标
- 复制图像路径以单击它
- 从模块内部访问Express装载路径
- 获取所有缓存资源文件的本地路径
- 即使文件路径正确,也无法从bower_components加载资源
- Wicket:资源路径听起来不起作用
- 钛移动的Commonjs资源路径
- 在javascript中添加静态资源的URL路径(在Spring MVC中)
- 文件资源管理器,存储路径
- JavaScript:cssText属性,如何在FireFox中获得使用外部资源的样式的绝对路径
- 嵌套的资源和路径
- Node.js:由于URL编码的GET参数,导致外部资源的路径混乱
- PhantomJS正在更新资源文件路径
- 当Servlet使用子路径时,不会检索诸如css或javascript之类的页面资源
- 控制mainBundle资源路径iOS开发
- 根据环境在Javascript中设置资源的新绝对路径
- 当使用Href标签时,SpringMVC资源路径会改变
- 无法获取资源路径
- WebView中文件的iOS Javascript资源路径