如何解决嵌套索引路由无法在插座中正确呈现
我正在尝试在taking-cash/index
的{{1}}内渲染taking-cash
:
{{outlet}}
:
router.js
除非我明确指定了 this.route('retirement-options',function () {
this.route('taking-cash');
路径,否则它不会在插座内渲染:
/index
为什么没有暗示 this.route('retirement-options',function () {
this.route('taking-cash',function() {
this.route('index',{ path: '' });
});
});
,我不能在/index
中指定它吗?
解决方法
Ember仅为具有至少一个其他子级的路由自动提供索引路由。
让我们看看您的示例:
this.route('retirement-options',function () {
this.route('taking-cash');
});
这将创建三条路线:
-
retirement-options
-
retirement-options.index
-
retirement-options.taking-cash
retirement-options.index
和retirement-options.taking-cash
共享相同的父路由retirement-options
。
retirement-options
本身不可导航。除非过渡明确指定了retirement-options.index
子路由,否则它将始终解析为taking-cash
路由。
在retirement-options.taking-cash
中添加另一个子路由后,Ember会自动为其为其创建索引路由。
您可以通过创建显示的路由来强制执行显式索引路由。但是,仅将索引路由作为叶节点并没有太大价值。
请在指南中找到有关索引路线的更多信息:https://guides.emberjs.com/release/routing/defining-your-routes/#toc_index-routes
,Ember实际上只会为路由自动提供索引路由,但是它不需要专门有子级。实际上,必须存在回调函数。
那么看这个例子,
this.route('retirement-options',function() {
this.route('taking-cash',function() {
this.route('index',{ path: '' });
});
});
索引部分不是必需的。声明了回调函数后,索引就会在那里。
这与上面的示例完全相同。
this.route('retirement-options',function() {});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。