AngularJS is cleaning the parameters of Url

1

I have a system with Angular and Java.

In the initial route I read the url parameters (some user information, such as code, etc.) and saved in $ rootScope to access throughout the application.

If I access directly through the browser, it works accordingly, the example of the link is this:

link

But I have another system that generates these links and e-mail some recipients, and they access from the email, with these parameters embedded in the url.

In these cases, Angular loads the main link, however it ends up clearing all the parameters, leaving the url just like this:

link

To read the parameters, I'm using $ location.search () with the Angular.

Edit:

  

I retrieve the parameters in the "module.run ()" from the application's Angle.

    function run($rootScope, $location) {

     var data = $location.search();

     if (data) {
         $rootScope.parametro1= data.parametro1;
         $rootScope.parametro2= data.parametro2;
     } 

   }
  

Angle Routes

function config($stateProvider, $urlRouterProvider) {

    //Route Default
    $urlRouterProvider.otherwise('/login');

    //Routes
    $stateProvider
        .state('login', {
            url: '/login',
            templateUrl: 'templates/login.html',
            controller: 'AuthenticationCtrl',
            controllerAs: 'vm'
        })

}
  

Login Controller

function AuthenticationCtrl($state, $rootScope, $location) {

   var vm = this;
   vm.init = init;

   init();

   function init() {

        //Faço o parse, pois esse parâmetro é sempre inteiro..
        vm.parametro1 = parseInt($rootScope.parametro1);
    }

}
  

Does anyone know why this behavior?   

How do I fix this?

    
asked by anonymous 09.05.2017 / 13:37

1 answer

1

Standard route handling does not preserve querystrings , and your route is not waiting for parameters. For all purposes, the route

#!/login?parametro1=10&parametro2=20

It is non-existent, so the URL Router forwards the user to the parameter set to .otherwise() .

If you want to receive parameters in your route, configure it as follows:

$stateProvider
    .state('login', {
        url: '/login/:parametro1/:parametro2',
        templateUrl: 'templates/login.html',
        controller: 'AuthenticationCtrl',
        controllerAs: 'vm'
    })

And issue your URLs in the following format:

#!/login/[parametro1]/[parametro2]

In your example, it looks like this:

#!/login/10/20
    
09.05.2017 / 16:13