Get previous location in Angularjs ui-router Get previous location in Angularjs ui-router angularjs angularjs

Get previous location in Angularjs ui-router


Use $state.href to get the url:

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {   // $state.href(from, fromParams)});

You can also pass options as a third paramerer.
Read the Docs for more information.


Not much differently, but you could do:

$rootScope.$on('$routeChangeStart', function (event, next, current) {});

And just store the current. The function there is a lot less to deal with than $routeChangesuccess.


using window.history.back() will return you to the previous url.