在我的应用程序中,如果我收到密码重置说明,我会使用如下网址访问服务器:
/changepass?key=1231231231212312
在 Controller 中我有这样的代码:
if (typeof $routeParams.key !== 'undefined') {
$scope.changePassword();
}
但是当我更改密码并想要在同一 View 中登录时,我转到另一个位置,但这个 ?key=123123123
仍然在那里。我做错了什么,如何在没有任何 key 的情况下进入空:/company?
$scope.login = function() {
***
$location.path('/company');
***
};
我也尝试了$scope.$apply($location.path('/company'));
但当我登录后去公司时,我的网址中仍然有参数。怎么解决这个问题?
在路由中:
.when('/signin', {
templateUrl: 'views/authorization.html',
controller: 'AuthorizationCtrl'
})
.when('/changepass', {
templateUrl: 'views/authorization.html',
controller: 'AuthorizationCtrl'
})
最佳答案
有两种方法可以实现这一目标
$location#url
$location.url($location.path('/company'));
$location.search
$location.search('key', null);
另请参阅
<小时/>不相关:
当你使用 angularjs 时,你可以使用它的内置函数,如 angular.isDefined
if(angular.isDefined($routeParams.key)){
$scope.changePassword();
}
关于javascript - AngularJS路由: unnecessary params in url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28167736/