ember.js - Ember JS - 从资源路由到路由
问题描述
我正在尝试将项目从 2.x 版更新和 ember 到 3.x 版,我的第一个问题是在路由文件中我得到 this.resouce 未定义。我相信这已被弃用。代码如下所示:
this.route('objects', function () {
this.route('search', { path: '/' }, function () {
this.resource('objects.items', { path: '/:search_id' }, function () {
this.resource('objects.item', { path: '/item/:item_id'}, function () {
this.route('general', { path: '/' });
this.route('tab', { path: '/tab/:tab' });
this.route('relations');
this.route('diagram');
this.route('comments');
this.route('sources');
this.route('views');
});
});
});
});
我试图简单地将资源更改为路由并赋予 resetNameSpace: true 属性,但没有帮助。我也尝试了各种组合,但没有运气。任何有经验的人都可以帮我重做这个路由以兼容最新的 ember 吗?
解决方案
由于this.resource()
实际上是一种旧的 Ember 重置命名空间的方法,该resetNameSpace: true
属性确实可以做到这一点!
因为您使用this.resource('objects.items')
了 ,所以您实际上创建了一个重置的命名空间,objects
路由所在的位置。
所以你的新路由器看起来像¹:
this.route('objects', function () {
this.route('search', { path: '/'});
this.route('items', { path: '/:search_id'});
this.route('item', { path: '/item/:item_id' }, function () {
this.route('general', { path: '/' });
this.route('tab', { path: '/tab/:tab' });
this.route('relations');
this.route('diagram');
this.route('comments');
this.route('sources');
this.route('views');
});
});
这样你仍然可以使用transitionToRoute("objects.item.general", id)
.
¹ 注意没有resetNameSpace
使用标志!
推荐阅读
- ios - inputAccessoryView 卡在屏幕底部
- git - 命名现有的 git stash
- javascript - 角脚本的颜色变化
- tsql - 将 Binary(64) 列中的值与 HASHBYTES('SHA2_512', 'SomeString') 返回的值进行比较
- javascript - 无法使用 Axios 在 formData 中发送数组
- python - 如何使用仅从某些网页上的文章中抓取数据
和
标签 - c# - 有没有办法在带有 sql server 2008 数据库的 vb.net 或 C# 桌面应用程序中嵌入 power bi 报表和仪表板?
- node.js - 如何使用 Electron JS 执行另一个程序
- arrays - 在不删除原始 UserDefault 信息的情况下将数组附加到 UserDefaults
- python - 如何在 R 中定义整数参数?(参数“a”缺失,没有默认值)