[英]Ember - prevent transition on route error
我在余燼路線上攔截了error
鈎子。 我正在頂層執行此操作,並從該類繼承我的所有路由。
我想做的是,當服務器返回401未經授權的響應時,我想顯示一條通知,指出用戶未經授權,並停留在同一頁面上。
到目前為止,我有這個:
Ember.Route = Ember.Route.extend(InfinityRoute, {
actions: {
error: function(error){
if (error.status === 401) {
this.store.createRecord('notice', {
message: "You are not authorized to view this content. Sorry man."
});
// Some code here ...
}
}
}
});
該通知有效,但是應用程序仍切換到新模板,該模板的內容為空,因為用戶無權查看它。
我希望我的應用程序停留在同一頁面上,而不要過渡到請求的頁面。
怎么樣?
我不確定,但是您可以嘗試willTransition
:
willTransition: function(transition) {
// inspect transition object to see if the error ocurred
}
也許會幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.