我想知道如何在不同的父路由中重用嵌套路由。 例如:
模板路线A: {{outlet}} - > routeX
模板路线B: {{outlet}} - > routeX
Router.map(function() {
this.route('routeA', function(){
this.route('routeX', {resetNamespace:true});
});
this.route('routeB', function(){
this.route('routeX', {resetNamespace:true});
});
})
我需要使用{{link-to' routeX'}}在当前父级中显示routeX。 在示例中,当我使用{{link-to' routeX'}}
时,始终会显示routeB我有2个aproax解决方案:
1)在routeA中放置1个子路由,在routeB中放置其他路由:
Router.map(function() {
this.route('routeA', function(){
this.route('routeX');
});
this.route('routeB', function(){
this.route('routeX');
});
})
并使用{{link-to' routeA.routeX'}}和{{link-to' routeB.routeX'}} 但在这个aproax我有一个重复的代码。
2)
router.map(function() {
this.route('*wildcard', function(){
this.route('routeX', {resetNamespace:true});
});
})
此选项有效,但在网址中显示" undefined" http://...undefined/routeX
有什么想法吗? 感谢
答案 0 :(得分:0)
如果可能,我建议使用组件或mixin来共享这两条相似路线之间所需的任何代码或功能。
看起来像这样
export default Ember.Mixin.create({
model() {
return Ember.Object.create({title: 'Awesome'})
}
});
然后在你的路线中使用它,就像这样,
import ReUseMixin from '../../mixins/re-use'
export default Ember.Route.extend(ReUseMixin,{
或定义您的组件,比如说re-use.hbs
和re-use.js
你可以在routeA / routeX和routeB / routeX中使用它
{{re-use}}
这是一个link到一个余烬,它展示了我的建议,希望能为你提供解决方案。