在我的路线
.when('/user:user_guid',{
templateUrl : 'users/profile.html',
controller : 'userController'
})
我index.html
中的ng-repeat
<a href="#/user/:{{user.user_guid}}">view profile</a>
它有效,但在我的网址中,我看到guid已经曝光。有没有办法隐藏它?
答案 0 :(得分:1)
使用ng-click
<a ng-click="go_url(user)">view profile</a>
然后在某个控制器中
//it has many possible solutions, this is one of them
//according to your config, you're using angular route provider
$scope.go_url = function(_user){
//be sure to inject $location service
$location.path('/user/' + _user.user_guid);
}
如果您不想在浏览器中公开网址,请使用可以在其中保存guid变量的服务,并在用户导航到/user
时抓取它
这是演示
angular.module('demo', ['ngRoute']);
angular.module('demo').config(function($routeProvider){
$routeProvider
.when('/welcome', {
templateUrl: 'welcome_page'
})
.when('/user', {
templateUrl: 'hello_page'
})
.otherwise({redirectTo: '/welcome'});
});
angular.module('demo').service('SecretServ', function(){
this.secret_guid = '';
});
angular.module('demo').controller('Controller1', function($scope, $location, SecretServ){
$scope.user = {
guid: '123345567234'
};
$scope.go = function(){
SecretServ.secret_guid = $scope.user.guid;
$location.path('/user');
};
});
angular.module('demo').controller('Controller2', function($scope, SecretServ, $location){
$scope.guid = SecretServ.secret_guid;
$scope.exit = function(){
$location.path('/welcome');
}
});
&#13;
<script src="https://code.angularjs.org/1.4.4/angular.js"></script>
<script src="https://code.angularjs.org/1.4.4/angular-route.js"></script>
<div ng-app="demo">
My app
<div ng-view></div>
<script id="welcome_page" type="text/ng-template">
<div ng-controller="Controller1">
Welcome<br>
To go to private page, click <button ng-click="go()">me</button>
</div>
</script>
<script id="hello_page" type="text/ng-template">
<div ng-controller="Controller2">
Hello {{guid}}, <button ng-click="exit()">exit</button>
</div>
</script>
</div>
&#13;
答案 1 :(得分:0)
您可以加密网址参数。然后在PHP中读取POST / GET参数时,先解密它然后读取值。这样就没有任何暴露。我已经完成了一些自己的项目,但它确实有效。