[英]Ember abort queryParams transition
我正在嘗試捕獲過渡,然后再進行一些檢查。 在幾乎所有用例中,我都能很好地完成它。
但是,我有一組僅更改queryParams
的鏈接。 當我在此鏈接上嘗試transition.abort()
時,出現錯誤。
這是我的模板:
{{#link-to (query-params date=nextWeek)}}next{{/link-to}}
並且,在路線上:
actions: {
willTransition (transition) {
transition.abort();
}
}
錯誤:
transitionByIntent@https://192.168.1.3/assets/vendor.js:62857:16
refresh@https://192.168.1.3/assets/vendor.js:62948:14
refresh@https://192.168.1.3/assets/vendor.js:37404:14
queryParamsDidChange@https://192.168.1.3/assets/vendor.js:37123:13
triggerEvent@https://192.168.1.3/assets/vendor.js:39417:13
trigger@https://192.168.1.3/assets/vendor.js:64310:7
fireQueryParamDidChange@https://192.168.1.3/assets/vendor.js:63092:7
getTransitionByIntent@https://192.168.1.3/assets/vendor.js:62785:5
transitionByIntent@https://192.168.1.3/assets/vendor.js:62855:16
refresh@https://192.168.1.3/assets/vendor.js:62948:14
refresh@https://192.168.1.3/assets/vendor.js:37404:14
queryParamsDidChange@https://192.168.1.3/assets/vendor.js:37123:13
triggerEvent@https://192.168.1.3/assets/vendor.js:39417:13
trigger@https://192.168.1.3/assets/vendor.js:64310:7
fireQueryParamDidChange@https://192.168.1.3/assets/vendor.js:63092:7
getTransitionByIntent@https://192.168.1.3/assets/vendor.js:62785:5
我截斷了錯誤消息。 基本上,它似乎一遍又一遍地嘗試進行過渡。
此外,盡管有錯誤,頁面仍會根據新參數進行刷新(不應刷新)。
題
如何捕獲僅在查詢參數中發生變化的過渡,以便我可以決定繼續還是abort
?
我知道有queryParamsDidChange
掛鈎。 我希望有queryParamsWillChange
。
您可以在路由中使用do_something
方法,並在willTransition中調用。
export default Ember.Route.extend({
_doSomething() {
//write your logic and return true if want to stop transition.
},
actions: {
willTransition(transition) {
//You can write doSomething logic here or you can write function and call
if (this._doSomething()) {
transition.abort();
}
return true;
}
}
})
注意: queryParamsDidChange
是私有方法。 可以在不通知的情況下更改此實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.