简体   繁体   English

灰烬中的路线刷新事件

[英]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. 我知道ember具有“ refresh()”方法,可以从路由内的某个位置调用它,但不能充当事件。 And, the 'willTransition' event only gets activated if the url path changes. 并且,仅当URL路径更改时,才会激活“ willTransition”事件。 There is also the 'activate()' event which only gets triggered upon entering the route. 还有一个“ activate()”事件,仅在输入路线时触发。

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. 您可以使用beforeModel挂钩。 Here you can save your transition, transition to another route (to show the message), and then .retry() your original transition. 在这里,您可以保存您的过渡,过渡到另一条路线(以显示消息),然后.retry()您的原始过渡。

This is basically how authentication works. 基本上,这就是身份验证的工作方式。 A good example is ember-simple-auth . 一个很好的例子是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! 我不确定100%想要做什么,在离开路线之前显示一条消息,或者在进入路线之前显示一条消息,但是beforeModel可能值得一看!

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

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