Reputation: 1073
I am a newbie of angularjs using angularjs1.6.4 version with angular-ui-router version 1.0.3. I have seen a lot of posts getting previous state by using $stateChangeSuccess
but this event is deprecated above ui-router version 1.0.0 (reference from here) so for that i have to use $transitions.onSuccess but i don't get it how to get previous state. So far i have written this and its displaying message "stateChange success" when state change. But i need some example to proceed further.
App.js:
.run(function ($transitions) {
$transitions.onSuccess({}, function () {
console.log("statechange success");
});
Upvotes: 0
Views: 3389
Reputation: 1073
This is what i want. An example for going back to a previous state with a refresh using $transitions.onSuccess instead of $stateChangeSuccess
.run(function ($transitions, $state) {
var previousState;
var previousStateParameters;
$transitions.onSuccess({}, function (transition) {
previousState = transition.from().name;
previousStateParameters = transition.params('from');
});
$transitions.back = function () {
$state.go(previousState, previousStateParameters, { reload: true });
}
});
Upvotes: 1