AngularJS:如何获取上一个网址并替换其参数?

时间:2017-09-15 06:18:59

标签: angularjs browser-history routeparams

我在我的应用程序中使用角度$routeProvider来更改网址。我想获取前一个url并替换它的一些路由参数。

$routeProvider.when("/editUser/:userId", {
  templateUrl: "app/user/userEdit.html", 
  controller: "UserCtrl"
});

例如,如果我之前的网址是上面的网址,我想将其参数userId更改为其他内容。 (上一个网址:/editUser/1,我想将其更改为:/editUser/2

我可以使用AngularJS做类似的事吗?

1 个答案:

答案 0 :(得分:0)

您可以为此目的使用角度路线更改事件,例如

$routeChangeStart, $routeChangeSuccess, $routeChangeError, $routeUpdate

这是一个例子

    $rootScope.$on('$routeChangeStart', function(event, next, current) {
        console.log("Next - "  + next.$$route.originalPath);
        console.log("Current - "  + current.$$route.originalPath);
    });

您可以将其存储在任何范围值中。