简体   繁体   中英

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 . In show-state.js I have tried putting this.transitionTo('routename') . I see that it works for routes other than showcountry . Complicating thing slightly is that in my router.js the entry looks something like the following 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 .

Please help.

transitionTo method if you are in route.

transitionToRoute method If you are in controller.

To transition to the same route, you can use refresh method . 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. Sample twiddle which demonstrate this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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