How can I retrieve the previous URL in AngularJS

前端 未结 3 1298
梦毁少年i
梦毁少年i 2021-01-21 15:16

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

3条回答
  •  再見小時候
    2021-01-21 15:54

    Angular $rootScope will have the all information across your all app components.

    Here below $location service injected on $rootscope will give you the route information.

    $rootScope.$on('$locationChangeStart', function (event, current, previous) {
            console.log("Previous URL" +previous);
    });
    

提交回复
热议问题