AngularJS - 改变$位置默默 - 删除查询字符串 [英] AngularJS - change $location silently - remove query string
问题描述
有没有办法使用默默改变地址栏的路线角?
Is there any way to silently change the route in the url bar using angular?
在用户点击进入链接的电子邮件:
The user clicks a link for the email that goes to:
/verificationExecuted?verificationCode=xxxxxx
在页面加载我想读验证code,然后清除:
When the page loads I want to read the verificationCode and then clear it:
if($location.path() == '/verificationExecuted'){
this.registrationCode = this.$location.search()["verificationCode"];
this.$location.search("verificationCode", null); //Uncomment but make this silent!
if(registrationCode != null) {
....
}
else $location.path("/404");
}
什么时,我清楚这是路径(/ verificationExecuted)的剩余部分会发生这样一遍周围带有没有验证code和直去404仍然击打路线重新触发。
What happens when I clear it is the remaining part of the route ("/verificationExecuted") remains buts the route re-triggers so it comes around again with no verificationCode and goes straight to 404.
我想删除code,而不做其他任何事情。
I want to remove the code without doing anything else.
推荐答案
您可以随时设置 reloadOnSearch
您的路线选择是假的。
这将prevent从重装如果只查询字符串改变路线:
It will prevent the route from reloading if only the query string changes:
$routeProvider.when("/path/to/my/route",{
controller: 'MyController',
templateUrl: '/path/to/template.html',
//Secret Sauce
reloadOnSearch: false
});
这篇关于AngularJS - 改变$位置默默 - 删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!