简体   繁体   中英

Route refresh event in Ember

I am interested in showing a modal on refreshing a certain route in an ember app. The modal will have an 'ok' action that will continue the route refresh and a 'cancel' action that will abort the refresh.

I know ember has the 'refresh()' method which can be called from somewhere within the route but cannot act as an event. And, the 'willTransition' event only gets activated if the url path changes. There is also the 'activate()' event which only gets triggered upon entering the route.

Is there a way to handle a route refresh event and also abort or continue the refresh based on a user action?

You can use the beforeModel hook. Here you can save your transition, transition to another route (to show the message), and then .retry() your original transition.

This is basically how authentication works. A good example is ember-simple-auth .

I'm not 100% sure what exactly you wanna do, a message to show before leaving a route, or a message before entering a route, but beforeModel is probably worth a look!

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