简体   繁体   English

如何从EmberJS中的组件过渡到相同的路线

[英]How to transition to the same route from a component in EmberJS

I have a main template say showcountry.hbs , inside that I am having a component show-state.hbs . 我有一个主模板showcountry.hbs ,里面有一个组件show-state.hbs In show-state.js I have tried putting this.transitionTo('routename') . show-state.js我尝试放置this.transitionTo('routename') I see that it works for routes other than showcountry . 我看到它适用于showcountry以外的其他路线。 Complicating thing slightly is that in my router.js the entry looks something like the following this.route('showcountry' , {path : '/app/mod/country' }); 稍微复杂的是,在我的router.js该条目看起来类似于以下this.route('showcountry' , {path : '/app/mod/country' });

I find that in component when I give the URL pattern in this.transitionTo it throws unrecognized URL error . 当我在this.transitionTo提供URL模式时,我在组件中找到了它,这将引发无法识别的URL错误。

Please help. 请帮忙。

transitionTo method if you are in route. 如果您在路线上,则采用transitionTo方法

transitionToRoute method If you are in controller. transitionToRoute方法(如果您在控制器中)。

To transition to the same route, you can use refresh method . 要过渡到相同的路线,可以使用refresh方法 So to resolve issue, you need to send action from component to route to call refresh method. 因此,要解决问题,您需要从组件发送操作以路由到调用刷新方法。

Note: if route is already rendered, then you can't transition to the current route, but if you use dynamic segments or queryParams then you can send that argument to transitionTo method which will call all the model hooks and re-render again. 注意:如果已经渲染了路线,则无法过渡到当前路线,但是如果使用动态线段queryParams,则可以将该参数发送到transitionTo方法,该方法将调用所有模型挂钩并再次重新渲染。 Sample twiddle which demonstrate this 样品旋转证明了这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM