我试图在不刷新我的页面的情况下更新一个 url,我正在使用这个解决方案:https://github.com/angular/angular.js/issues/1699#issuecomment-45048054
我注意到这段代码有效:
$route.current.pathParams.program = "someValue";
$location.path('/myapp/' + $routeParams.program);
但是这段代码不起作用:
$routeParams.program = "someValue";
$location.path('/myapp/' + $routeParams.program);
我想知道有什么区别,为什么一个有效而另一个无效?
最佳答案
它不起作用,因为 AngularJS 无法识别对 $routeParams
的任何更改,直到路由更改后,根据 documentation
Note that the $routeParams are only updated after a route change completes successfully. This means that you cannot rely on $routeParams being correct in route resolve functions. Instead you can use $route.current.params to access the new route's parameters.
关于javascript - $route.current.pathParams 和 $routeParams 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30762661/