我正在尝试捕获转换以在继续之前运行一些检查。在几乎我的所有用例中,我都可以完成它。
但是,我有一组仅更改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
我截断了错误消息。基本上它似乎是一遍又一遍地尝试进行转换。
此外,尽管存在错误,但页面会根据新参数刷新(不应该)。
问题
如何在JUST更改查询参数时捕获转换,以便我可以决定继续进行还是abort
?
我知道有queryParamsDidChange
钩子。我希望有queryParamsWillChange
。
答案 0 :(得分:0)
您可以在路线中使用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
是私有方法。无需随时通知即可更改此实现。