Hide param value (guid) in an URL

后端 未结 2 1290
予麋鹿
予麋鹿 2021-01-24 03:23

In my route

.when(\'/user:user_guid\',{
        templateUrl : \'users/profile.html\',
        controller : \'userController\'
    })

In my

2条回答
  •  被撕碎了的回忆
    2021-01-24 04:15

    Use ng-click

    view profile
    

    and then in some controller

    //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);
    }
    

    If you don't want to expose URL in browser, use service that can hold guid variable inside, and grab it when user navigates to /user


    Here's the demo

    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');
        }
      });
    
    
    
    
    
    My app

提交回复
热议问题