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()
Angular $rootScope will have the all information across your all app components.
$rootScope
Here below $location service injected on $rootscope will give you the route information.
$location
$rootscope
$rootScope.$on('$locationChangeStart', function (event, current, previous) { console.log("Previous URL" +previous); });