I know I can get the current URL using $location.search() and $location.path() but I need a way to get previous one. Can I use a global variable or so
$location.search()
$location.path()
You can use for example ui-router to control the flow of your application and with this library it's easy to implement previousState by saving it in $stateChangeSuccess event.