我尝试在不刷新页面的情况下更新网址,并且我正在使用此解决方案:https://github.com/angular/angular.js/issues/1699#issuecomment-45048054
我注意到此代码有效:
return publicKey.toString();
但是这段代码不起作用:
$route.current.pathParams.program = "someValue";
$location.path('/myapp/' + $routeParams.program);
我想知道差异是什么,为什么一个有效而另一个无效?
答案 0 :(得分:4)
它不起作用,因为根据documentation
,AngularJS在路线更改之前无法识别$routeParams
的任何更改
请注意,$ routeParams仅在路由更改后更新 成功完成。这意味着你不能依赖 $ routeParams在路由解析函数中是正确的。相反,你可以 使用$ route.current.params访问新路由的参数。