I adjusted your approach below. We will profit from decorating, but not of the directive. As we can check here, in the ui-sref
directive source code, the click event in fact does call:
$state.go(ref.state, params, options);
So, we can decorate the $state
provider, which could be very straightforward:
.config(function ($provide) {
$provide.decorator('$state', function ($delegate) {
// let's locally use 'state' name
var state = $delegate;
// let's extend this object with new function
// 'baseGo', which in fact, will keep the reference
// to the original 'go' function
state.baseGo = state.go;
// here comes our new 'go' decoration
var go = function (to, params, options) {
options = options || {};
// only in case of missing 'reload'
// append our explicit 'true'
if (angular.isUndefined(options.reload)) {
options.reload = true;
}
// return processing to the 'baseGo' - original
return this.baseGo(to, params, options);
};
// assign new 'go', right now decorating the old 'go'
state.go = go;
return $delegate;
});
})
And that's enough. Now any state change (including click on ui-sref
) will trigger reload
.
Note: Just must say, that I do not think that this is the way. Triggering reload all the time ... to me it seems that we in fact loose a lot, loose the advantages coming with that diamond - ui-router
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…