我想找到一种方法来重定向到索引路由,如果访问父路由但不重定向,如果用户访问parent.child1或parent.child2路由。重定向到仅索引父路由
是这样的可能吗?
this.route('parent', function() {
this.route('child1');
this.route('child2');
});
我想找到一种方法来重定向到索引路由,如果访问父路由但不重定向,如果用户访问parent.child1或parent.child2路由。重定向到仅索引父路由
是这样的可能吗?
this.route('parent', function() {
this.route('child1');
this.route('child2');
});
把里面parent
航线的beforeModel
钩您的重定向状态。
请参考Lux的答案。请使用您的父路由下index
路线,
ember g route parent/index
然后把你的重定向逻辑父/指数航线的beforeModel
钩内。
我以前的答案不会工作,因为它会阻止进入的小孩路线。
这会阻止你输入'child1'或'child2'。 – Lux
只有当某个contione遇到否则什么都不做,路由只能重定向吗? –
是的,勒克斯你是对的,他也可以在'parent.index'路线里面做。但是,在那种情况下,他必须生成一个新的“索引”路由,因为它还不存在。 –
如果我理解你正确地希望得到以下
如果用户是在
parent
路线,但不是在child1
,而不是在child2
路由重定向到index
路线。
为此,您需要了解您有一个隐含的parent.index
路线。因此,与您的路线定义,这是你的路线:
index
parent.index
parent.child1
parent.child2
你不能只是在路由parent
!您总是在parent.index
,parent.child1
或parent.child2
。
所以我想你想要的是从parent.index
重定向到index
。
为此仅创建app/routes/parent/index.js
路线,并在beforeModel
挂钩电话this.transitionTo('index');
。
谢谢,正是我想要的! – jpoiri
如果你能描述你的问题以及你认为这可能会解决问题会更好。 –