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

时间:2021-09-24 19:42:29

I am using angular $routeProvider in my application to change the urls. I want to get the previous url and replace some of its route parameters.

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

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

For example, if my previous url is the above one, I want to change it's parameter userId into something else. (previous url: /editUser/1, I want to change it to: /editUser/2)

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

Can I do something like that using AngularJS?

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

1 个解决方案

#1


0  

You can use angular route change events for this purpose, such as

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

$routeChangeStart, $routeChangeSuccess, $routeChangeError, $routeUpdate

Here is an example

这是一个例子

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

You can store this in any scope values.

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

#1


0  

You can use angular route change events for this purpose, such as

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

$routeChangeStart, $routeChangeSuccess, $routeChangeError, $routeUpdate

Here is an example

这是一个例子

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

You can store this in any scope values.

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